abstract-class

abstract method signature, inheritance, and "Do" naming convention

I'm learning about design patterns and in examples of code I've seen a convention where the abstract class declares a method, for example: public abstract class ServiceBase { ... public virtual object GetSomething(); and then protected abstract object DoGetSomething(); My question is on why these two methods exist, since they app...

XML Schema for a .NET type that inherits and implements

Hi, Please consider the following three .NET types: I have an interface, an abstract class, and a concrete class. My question is how to write the XML Schema to include the properties from the interface and from the abstract class. public interface IStartable { bool RequiresKey { get; set; } void Start(object key); } public a...

Calling private parent class method from parent class (django)

I want to call a redefined private method from an abstract parent class. I am using django if that matters. class Parent(models.Model): def method1(self): #do somthing self.__method2() def method2(self): pass # I also tried calling up a prent method with super class child(Parent): def method1(sel...

Inheritance of Custom Attributes on Abstract Properties

I've got a custom attribute that I want to apply to my base abstract class so that I can skip elements that don't need to be viewed by the user when displaying the item in HTML. It seems that the properties overriding the base class are not inheriting the attributes. Does overriding base properties (abstract or virtual) blow away att...

(C++) using a method of an abstract class

is it possible to use a method of an abstract class? how can i use a method of a class without having an instance? ...

Deriving a class from an abstract class (C++)

I have an abstract class with a pure virtual function f() and i want to create a class inherited from that class, and also override function f(). I seperated the header file and the cpp file. I declared the function f(int) in the header file and the definition is in the cpp file. However, the compiler says the derived class is still abst...

Implementing a Version check between an Abstract class and it's implementation

I have this abstract class and concrete implementation (they are in different assemblies): public abstract class MyAbstractClass { private static readonly int MyAbstractClassVersion = 1; public abstract int ImplementedVersion { get; } protected MyAbstractClass() { CheckVersion(); } private void CheckVe...

Can I use an abstract class instead of a private __construct() when creating a singleton in PHP?

When creating a Singleton in PHP, I ensure that it cannot be instantiated by doing the following: class Singleton { private function __construct() {} private function __clone() {} public static function getInstance() {} } However, I realised that defining a class as 'abstract' means that it cannot be instantiated. So is ...

How do I ensure my abstract class's function can only operate on extenders of the same type as the caller?

For example, let's say this is my abstract class: abstract class A{ int x; int y; void foo(A fooMe); } ...and B and C are two classes which extend A. What I want is for B to only be able to call foo() on other Bs, and for C to only be able to call foo() on other Cs. But I want this to be out of the hands of the programme...

How to write a cctor and op= for a factory class with ptr to abstract member field?

I'm extracting files from zip and rar archives into raw buffers. I created the following to wrap minizip and unrarlib: Archive.hpp - Used to access everything. If I could make all the functions in the other classes inaccessible from the outside, I would. (Actually, I suppose I could friend all the other classes in Archive and use privat...

iPhone -- init method of an abstract class

I want to create classes Car, Vehicle, and Airplane with the following properties: Car and Airplane are both subclasses of Vehicle. Car and Airplane both have an initWithString method. The acceptable input strings for Car's and Airplane's initWithString methods do not overlap. Vehicle is "almost abstract", in the sense that any initial...

Linker error: wants C++ virtual base class destructor

Hi, I have a link error where the linker complains that my concrete class's destructor is calling its abstract superclass destructor, the code of which is missing. This is using GCC 4.2 on Mac OS X from XCode. I saw http://stackoverflow.com/questions/307352/g-undefined-reference-to-typeinfo but it's not quite the same thing. Here is t...

When to use abstract classes?

Here is the msdn article on abstract class but i really dont get it... When should i really use abstract classes? What are the advantages of using abstract classes? ...

What's safe to assume about the NSMutableArray / NSArray class cluster?

I know you shouldn't use this to decide whether or not to change an array: if ([possiblyMutable isKindOfClass:[NSMutableArray class]]) But say I'm writing a method and need to return either an NSMutableArray or an NSArray, depending on the mutability of possiblyMutable. The class using my method already knows whether or not it's accep...

Ruby Abstract Class Design

I'm creating a video game. It has Characters & Items. Since I want Characters & Items to each have a name, should I make another class called NamedObjects with just a name field and have Characters & Items extend that? Or is that going overboard? ...

How to add member variable to an interface in c#

I know this may be basic but I cannot seem to add a member variable to an interface. I tried inheriting the interface to an abstract class and add member variable to the abstract class but it still does not work. Here is my code: public interface IBase { void AddData(); void DeleteData(); } public abstract class AbstractBase : IBas...

I need an abstract field !

I know abstract fields do not exist in java. I also read this question but the solutions proposed won't solve my problem. Maybe there is no solution, but it's worth asking :) Problem I have an abstract class that does an operation in the constructor depending on the value of one of its fields. The problem is that the value of this fiel...

Abstract class and constructor

As an abstract class cannot be instantiated, why is a constructor still allowed inside the abstract class? public abstract class SomeClass { private string _label; public SomeClass(string label) { _label=label; } } ...

Java inheritance question

I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend class Airplane. I also have an interface Measurable, and two classes that implement it - People and Containers. So, Airplane can do many things on its own, and there is a method which allows measurable things to be added to the airplane (...

My abstract class implements an interface but doesn't implement some of its methods. How do I make it compile?

interface ICanvasTool { void Motion(Point newLocation); void Tick(); } abstract class CanvasTool_BaseDraw : ICanvasTool { protected abstract void PaintAt(Point location); public override void Motion(Point newLocation) { // implementation } } class CanvasTool_Spray : CanvasTool_BaseDraw { protected a...