abstract-class

Static Methods in an Interface/Abstract Class

First off, I understand the reasons why an interface or abstract class (in the .NET/C# terminology) cannot have abstract static methods. My question is then more focused on the best design solution. What I want is a set of "helper" classes that all have their own static methods such that if I get objects A, B, and C from a third party ...

Please help me with my .NET abstract classes.

I'm designing a web site navigation hierarchy. It's a tree of nodes. Most nodes are pages. Some nodes are links (think shortcuts in Windows). Most pages hold HTML content. Some execute code. I'd like to represent these as this collection of classes and abstract (MustInherit) classes This is the database table where I'm going to ...

Performance penalty for working with interfaces in C++?

Is there a runtime performance penalty when using interfaces (abstract base classes) in C++? ...

Is there a way to implement algebraic types in Java?

Is it possible, in Java, to enforce that a class have a specific set of subclasses and no others? For example: public abstract class A {} public final class B extends A {} public final class C extends A {} public final class D extends A {} Can I somehow enforce that no other subclasses of A can ever be created? ...

C# Abstract class, using anonymous instead of declaring concrete class?

I have an abstract class and I would like to use it quickly by NOT create a concrete class that inherit the abstract class. Well, to define the abstract method anonymously. Something like that: Command c = new Command(myObject){ public override void Do() { } ...

Why an abstract class implementing an interface can miss the declaration/implementation of one of the interface's methods?

A curious thing happens in Java when you use an abstract class to implement an interface: some of the interface's methods can be completely missing (i.e. neither an abstract declaration or an actual implementation is present), but the compiler does not complain. For example, given the interface: public interface IAnything { void m1()...

abstract methods in skeletal implementations of interfaces

I was re-reading Effective Java (2nd edition) item 18, prefer interfaces to abstract classes. In that item Josh Bloch provides an example of a skeletal implementation of the Map.Entry<K,V> interface: // Skeletal Implementation public abstract class AbstractMapEntry<K,V> implements Map.Entry<K,V> { // Primitive operations ...

Exact use of Abstract class

What is the exact use of an Abstract class? Is not possible to do the same things in an ordinary class as it is an an abstract class? ...

Can I force subclasses to override a method without making it abstract?

I have a class with some abstract methods, but I want to be able to edit a subclass of that class in the designer. However, the designer can't edit the subclass unless it can create an instance of the parent class. So my plan is to replace the abstract methods with stubs and mark them as virtual - but then if I make another subclass, I...

Best practice Unit testing abstract classes?

Hello I was wondering what the best practice is for unit testing abstract classes and classes that extend abstract classes. Should I test the abstract class by extending it and stubbing out the abstract methods and then test all the concrete methods? Then only test the methods I override and the abstract methods in the unit tests for o...

Abstract class constructor in Java

Can an abstract class have a constructor? If so, how it can be used and for what purposes? ...

Is there a benefit to having both an abstract class and an interface?

I started out with a generic interface called ILogin. The interfaces requires that you implement two properties: UserID and Password. I have many login-type classes that implement this interface. As my project grew and grew, I found that many classes repeated the UserID and Password code. Now I decide that I need a base Login class. ...

If abstract base C++ class is actually an interface, so it own no data members, is it obligatory to call base class constructor in derived class constructor?

I have a code: class AbstractQuery { virtual bool isCanBeExecuted()=0; public: AbstractQuery() {} virtual bool Execute()=0; }; class DropTableQuery: public AbstractQuery { vector< std::pair< string, string> > QueryContent; QueryValidate qv; public: explicit DropTableQuery(const string& qr): AbstractQuery(), qv(q...

Visual Studio: How do I show all classes inherited from a base class?

In Visual Studio, How do I show all classes inherited from a base class? For example, in ASP.NET MVC there are several 'ActionResult' types -- and they all inherit from / implement the base class 'ActionResult'. It looks like unless you just 'know' that 'View' and 'Json' are valid 'ActionResult' types, there is no way you can easil...

Should Helper/Utility Classes be abstract?

I commonly find myself extracting common behavior out of classes into helper/utility classes that contain nothing but a set of static methods. I've often wondered if I should be declaring these classes as abstract, since I can't really think of a valid reason to ever instantiate these? What would the Pros and Cons be to declaring suc...

Deriving an abstract class from concrete class

Let's say we have a concrete class Apple. (Apple objects can be instantiated.) Now, someone comes and derives an abstract class Peach from Apple. It's abstract because it introduces a new pure virtual function. The user of Peach is now forced to derive from it and define this new function. Is this a common pattern? Is this correct to do?...

How do you declare an interface in C++?

How do I setup a class that represents an interface? Is this just an abstract base class? ...

Can I specify a non strict method requirement for child classes? [PHP]

I have a base class in which I want to specify the methods a child class must have, but not implement them itself. However, the methods in a child class may have a different number of paramaters to the definition in the base class. Having tried this with an abstract method, php doesn't allow this. Is it possible? ...

Abstract class with all concrete methods

Are there some practical programming situations for someone to declare a class abstract when all the methods in it are concrete? ...

Why can't static methods be abstract in Java

The question is in Java why can't I define an abstract static method? for example abstract class foo { abstract void bar( ); // <-- this is ok abstract static void bar2(); //<-- this isn't why? } ...