abstract-class

Difference between abstract class and interface in Python

What is the difference between abstract class and interface in Python? ...

Registering derived classes in C++

EDIT: minor fixes (virtual Print; return mpInstance) following remarks in the answers. I am trying to create a system in which I can derive a Child class from any Base class, and its implementation should replace the implementation of the base class. All the objects that create and use the base class objects shouldn't change the way th...

Abstract classes and methods in Java, Inheritance

Hello, I have class B, which inherits from class A. The superclass A is abstract, containing one abstract method. I don't want to implement the abstract method in class B, therefore I need to declare class B as abstract as well. Declaring class B abstract, two things are working for me (the programs compile and run correctly): 1.) I do...

Is this design a good idea - Interfaces and Abstract class

I would like to be able to do somthing like the following: //non-generic var MyTable = new Table(); string name = MyTable.Name; IEnumerable<String> rows = MyTable.Rows; //generic var MyTableGeneric = new Table<MyType>(); string name = MyTableGeneric.Name; IEnumerable<MyType> rows = MyTableGeneric .Rows; Would something like this be t...

ASP.NET Controller Base Class User.Identity.Name

Hi folks As described in this post, I created an abstract base controller class in order to be able to pass data from a controller to master.page. In this case, I want to lookup a user in my db, querying for User.Identity.Name (only if he is logged in). However, I noticed that in this abstract base class the User property is always nul...

Naming conventions for abstract classes

I distinctly remember that, at one time, the guideline pushed by Microsoft was to add the "Base" suffix to an abstract class to obviate the fact that it was abstract. Hence, we have classes like System.Web.Hosting.VirtualFileBase, System.Configuration.ConfigurationValidatorBase, System.Windows.Forms.ButtonBase, and, of course, System.Col...

Java: Interface vs Abstract Class (regarding fields)

From what I have gathered, I want to force a class to use particular private fields (and methods) I need an abstract class because an interface only declares public/static/final fields and methods. Correct?? I just started my first big java project and want to make sure I'm not going to hurt myself later :) ...

Casting to abstract class or interface when generics are used

I have this method Verify_X which is called during databind for a listbox selected value. The problem is the strongly typed datasource. I want to use the abstract class BaseDataSource or an interface to call the methods supported: Parameters[] and Select(), Instead of using the most specific implementation as seen below. This is so on...

When to use an interface instead of an abstract class and vice versa?

This may be a generic OOP question. I wanted to do generic comparison between an interface and an abstract class on the basis of their usage. When would one want to use and interface and when would on want to use an abstract class? ...

Pure Virtual Method VS. Function Pointer

Hey all, Recently I've been designing a Thread class library, I've made a Thread abstract class like the following: class Thread { public: run() { /*start the thread*/ } kill() { /*stop the thread*/ } protected: virtual int doOperation(unsigned int, void *) = 0; }; Real thread classes would inherit this abstract class and ...

Why can't I create an abstract constructor on an abstract C# class?

I am creating an abstract class. I want each of my derived classes to be forced to implement a specific signature of constructor. As such, I did what I would have done has I wanted to force them to implement a method, I made an abstract one. public abstract class A { abstract A(int a, int b); } However I get a message saying the a...

How to implement an abstract class in ruby?

I know there is no concept of abstract class in ruby. But if at all it needs to be implemented, how to go about it? I tried something like... class A def self.new raise 'Doh! You are trying to instantiate an abstract class!' end end class B < A ... ... end But when I try to instantiate B, it is internally going to call A....

C#: Creating an instance of an abstract class without defining new class

I know it can be done in Java, as I have used this technique quite extensively in the past. An example in Java would be shown below. (Additional question. What is this technique called? It's hard to find an example of this without a name.) public abstract class Example { public abstract void doStuff(); } public class StartHere{ p...

Django: retrieving abstract-derived models

After getting fine answer to my previous question, I came across another problem. I followed the third approach, being aware of what djangodocs say about abstract model subclassing. I am using the latest Django, rev 9814. The strange behaviour I get: In [1]: o = Order() In [2]: o.save() DEBUG:root:STORING EVENT MESSAGE: Order created...

Abstract Class - Am I over-thinking this or doing it right?

So I am utilizing CollectionBase as an inherited class for custom collections. I am utilizing CollectionBase through an abstract class so that I don't repeated knowledge (following the DRY principle). The abstract class is defined as a generic class also. Here is how I am implementing my class: public abstract class GenericCollecti...

How do you decide between using an Abstract Class and an Interface?

Duplicate: http://stackoverflow.com/questions/56867/interface-vs-base-class I have been getting deeper into the world of OOP, design patterns, and actionscript 3 and I am still curious how to know when to use an Abstract class (pseudo for AS3 which doesn't support Abstract classes) and an interface. To me both just serve as templates...

Separate header files for concrete classes - C++

Background I have an abstract class, something like class IConverter{ public: virtual void DoConvertion() = 0; }; There will be many concrete classes which just implements DoConvertion method. class TextConverter : public IConverter{ public: virtual void DoConvertion(){ // my code goes here } }; class ...

C# Serializing and restoring an unknown class

A base project contains an abstract base class Foo. In separate client projects, there are classes implementing that base class. I'd like to serialize and restore an instance of a concrete class by calling some method on the base class: // In the base project: public abstract class Foo { abstract void Save (string path); abstra...

What is the difference between an Abstract Class and a Mixin?

I just found an article on a framework in Java that apparently allows it to support Mixins and something called Composite Oriented Programming (which for all I know might even be the same thing...) I've also heard of/worked with AOP, and I'm not sure how it differs from this either... ...

Template or abstract base class?

If I want to make a class adaptable, and make it possible to select different algorithms from the outside -- what is the best implementation in C++? I see mainly two possibilities: Use an abstract base class and pass concrete object in Use a template Here is a little example, implemented in the various versions: Version 1: Abstract...