abstract-class

abstract classes and interfaces best practices in java

So you've got an interface and an abstract class that implements a subset of the methods in the interface. You've also got some classes that inherit the abstract class and give implementations of the methods the abstract class doesn't give. So what's the best practice here? I'm talking about issues like: 1) Should the abstract class im...

abstract-class in java

Is possible to create objects of an abstract class in Java ...

Abstract class design

Is this an acceptable design ?? Abstract class public abstract class SomethingBase { public abstract int Method1(int number1); public abstract int Method2(int number2); } public class Class1 : SomethingBase { public override int Method1(int number1) { //implementation } //i dont want this method in this cla...

Strategy Pattern with Different parameters in interface (C#)

I am basically trying to implement a Strategy pattern, but I want to pass different parameters to the "interfaces" implementation (that inherit from the same object) and don't know if this is possible. Maybe I'm choosing the wrong pattern, I get an error similar to 'StrategyA' does not implement inherited abstract member 'void DoSomet...

How do I specify that an implementing class must contain a particular field?

I would like to write an abstract class (or interface) which either Forces all implementing classes to provide a field (ideally static) of a particular type and name (maybe by throwing a compile-time error if it's missing?), or Automatically provides such fields in implementing classes. An example would be: public abstract class A {...

Need help for C# abstract properties sample code dissection

When reading the tutorial of "Properties Tutorial" from MSDN. I'm consused about the example. How to define abstract properties. ... When I debug, I found each of the three override double Area() is invoked by ToString(); and ToString() is invoked default by the WriteLine() calls. What's the benefit calling this way? I feel it is ...

Difference between Abstract Class and Trait

What is the conceptual difference between abstract classes and traits? ...

Using vb.net dll in c++ - class is abstract

I created a vb.net dll which I am using in an unmanaged c++ project. When I try to create an object of the class, I am getting an error: cannot instantiate abstract class Why would my class be abstract? How can I modify it so that it won't be abstract? ...

Java polymorphism/abstract class help

I'm trying to set parameters for a abstract class: public abstract class NewMath { public abstract int op (int intOne, int intTwo); } Here is the extended subclass: public class MultMath extends NewMath { public int op (int intOne, int intTwo){ return intOne + intTwo; } } But when I try to instantiate an object ...

Strange behaviour with parameterized method on abstract class

Hi. Can someone tell my why this gives a compile error? I don't see why the cast to A in the second for-loop causes strings() to return a general List of Objects. import java.util.ArrayList; import java.util.List; public class E { public static void main(String[] args) { for (String s : new D().strings()) { Sys...

c# - How to do MULTIPLE "mixins" correctly with Interfaces and/or Abstract Classes

I want to be able to define some objects and attach some "behaviors" to that object where the implementation is in the behavior not in the object. Rails-like: acts_as_taggable. As a concrete example, I want to say that Tasks can be Tagged. I don't want to have to code anything in Task about Tags beyond "enabling" the behavior via ... ...

How to access functions from abstract class without making them static ?

I want to create a class that can only be inherited, for that i know it should be made abstract. But now the problem is that i want to use functions of that class without making them static. How can i do that. public abstract Class A { A() {} public void display() {} } public Class B:A { base.A() // this is accessible this.displ...

Abstract classes issue in C++ undo/redo implementation

I have defined an "Action" pure abstract class like this: class Action { public: virtual void execute () = 0; virtual void revert () = 0; virtual ~Action () = 0; }; And represented each command the user can execute with a class. For actual undo/redo I would like to do something like this: Undo Action a = historyStack.p...

Inherited class "invalid pointer error" when calling virtual functions.

As you can see in the code below, I have an Abstract Base Class "HostWindow", and class that derives from it "Chrome". All the functions are implemented in Chrome. The issue is, I can't call functions in Chrome if they're virtual. class HostWindow : public Noncopyable { public: virtual ~HostWindow() { } // Pure virtual function...

Avoiding #import of header for abstract-only parent class

I develop CHDataStructures, a library of Cocoa data structures to supplement those in Foundation. It includes a fair number of classes (stacks, queues, and dequeues) that share common implementation details, so it makes sense to design them with a common parent class which I treat as abstract (Objective-C doesn't natively enforce this co...

unable to successfully call function in dynamically loaded plugin in c++

I've successfully loaded a C++ plugin using a custom plugin loader class. Each plugin has an extern "C" create_instance function that returns a new instance using "new". A plugin is an abstract class with a few non-virtual functions and several protected variables(std::vector refList being one of them). The plugin_loader class success...

Constructors in Abstract Classes?

Possible Duplicate: Abstract class constructor in Java When we can't create an instance of abstract class, what is the purpose of a constructor? ...

Why can't we create objects for an abstract class in C++?

I know it is not allowed in C++, but why? What if it was allowed, what would the problems be? ...

What is the use of creating a constructor for an abstract class in Java?

I would like to know what purpose a constructor for an abstract class serves; as we do not instantiate abstract classes, why would we ever need such a constructor? ...

Why java.lang.Object is not abstract?

Why is the Object class, which is base class of 'em all in Java, not abstract? I've had this question for a really really long time and it is asked here purely out of curiosity, that's all. Nothing in my code or anybody's code is breaking because it is not abstract, but I was wondering why they made it concrete? Why would anyone want a...