abstract-class

model an abstract base class and subclasses in a database

I have 4 subclasses: Video, Image, Note, and Form. Each one contains different types of data. For example, the Image class contains a path to the image file on disk and image properties, and the Form class contains the form field values. The common element between each item, however, is the GPS coordinates and heading, so I have the foll...

Refactoring abstract Java class with many child classes

I'm looking for ideas on the best way to refactor this scenario (better design, minimal effort). Starting from the following example abstract class (actual has many more fields, methods and abstract methods) : abstract class Car { private int manufactureYear; // ... many more fields that are hard to clone public Car(int ma...

Call a class inside another class in PHP

Hey there I'm wondering how this is done as when I try the following code inside a function of a class it produces some php error which I can't catch public $tasks; $this->tasks = new tasks($this); $this->tasks->test(); I don't know why the initiation of the class requires $this as a parameter either :S thanks class admin { func...

abstract class with published Api but default access constructor

In the MIDP api there is a public abstract class Layer, this class has a javadoc published however it doesn't show a constructor in the javadoc. In the same api there are two other classes Sprite and TiledLayer. public class Sprite extends Layer public class TiledLayer extends Layer All these classes are in the package javax.microed...

Copy constructor: deep copying an abstract class

Suppose I have the following (simplified case): class Color; class IColor { public: virtual Color getValue(const float u, const float v) const = 0; }; class Color : public IColor { public: float r,g,b; Color(float ar, float ag, float ab) : r(ar), g(ag), b(ab) {} Color getValue(const float u, const float v) const ...

Does an abstract class work with StructureMap like an interface does?

I am a big fan of StructureMap and use it in just about everything I do. I have only ever used it with interfaces though. I was wondering if anyone had any experience using with abstract classes? or...does it not support that type of wiring? If you got this to work can you post an example? Thanks! ...

Java Puzzler - Can anyone explain this behavior ?

abstract class AbstractBase { abstract void print(); AbstractBase() { // Note that this call will get mapped to the most derived class's method print(); } } class DerivedClass extends AbstractBase { int value = 1; @Override void print() { System.out.println("Value in DerivedClass: " + va...

in PHP, when should I use static methods vs abstract classes?

I'm under the interpretation that if I need to access a method statically, I should make the class abstract only if I'll never need it instantiated. Is that true? ...

AS3 - Abstract Classes

How can I make an abstract class in AS3 nicely? I've tried this: public class AnAbstractClass { public function toBeImplemented():void { throw new NotImplementedError(); // I've created this error } } public class AnConcreteClass extends AnAbstractClass { override public function toBeImplemented():void { ...

Why is my nest class being seen as abstract?

I have an abstract base class which contains a private nested implementation. visual c++ is giving me the following error when I try to instantiate the non-abstract nested implementation: error C2259: 'node::empty_node' : cannot instantiate abstract class (line 32) as far as I can tell, I've overridden all the abstract members of the ...

Accessing a method from a templated derived class without using virtual functions in c++?

How do I get around this? I clearly cannot make the value() method virtual as I won't know what type it is beforehand, and may not know this when accessing the method from b: class Base { public: Base() { } virtual ~Base() { } private: int m_anotherVariable; }; template <typename T> class Derived : public Base { public: ...

Why is my Polymorphic Parent class calling the Subclass Method from within itself?

Heres the code I've made up so far. Its fully functional and the only gripe I have with it is that my output for Weekly and Annual pay is always weekly...I'm at a loss as to how to get this from within either toString method. public class PolyEmployees { public static void main(String[] args) { Employee [] myEmployees = { ...

Using an abstract class to implement a stack of elements of the derived class

I have to do this for a basic C++ lecture at my university, so just to be clear: i would have used the STL if i was allowed to. The Problem: I have a class named "shape3d" from which i derived the classes "cube" and "sphere". Now i have to implement "shape3d_stack", which is meant be able of holding objects of the types "cube" and "sphe...

Using shared_ptr in dll-interfaces.

I have an abstract class in my dll. class IBase { protected: virtual ~IBase() = 0; public: virtual void f() = 0; }; I want to get IBase in my exe-file which loads dll. First way is to create following function IBase * CreateInterface(); and to add the virtual function Release() in IBase. Second way is to create a...

Abstract Base Class and data members? How does it work?

An abstract base class (ABC) can have data to support the classes that inherit form it. However, given that its not possible to instantiate an object of an ABC how does the compiler handle this data for cases where we have a number of derived class objects that inherit the ABC. Does the data become associated with the derived class obje...

Abstract base class inheritance in Django with foreignkey

I am attempting model inheritance on my Django powered site in order to adhere to DRY. My goal is to use an abstract base class called BasicCompany to supply the common info for three child classes: Butcher, Baker, CandlestickMaker (they are located in their own apps under their respective names). Each of the child classes has a need fo...

C++ Functions for an Abstract Base Class

Suppose I want to have an inheritance hierarchy like this. class Base class DerivedOne : public Base class DerivedTwo : public Base The base class is not meant to be instantiated, and thus has some pure virtual functions that the derived classes must define, making it an abstract base class. However, there are some functions that y...

Need some help sorting out a major abstract pattern headache within my DAL

I've caused myself a bit of an issue with my Data Access Layer. In this particular instance, I have a table that contains potentially 5 types of 'entity'. These are basically Company, Customer, Site, etc. The type is dictated by a PositionTypeId within the table. They're all in the same table as they all havethe same data structure; Posi...

How do I compare two objects based on their base class?

I would like to be able to compare two classes derived from the same abstract class in C#. The following code illustrates my problem. I now I could fix the code by making BaseClass non abstract and then return a new BaseClass object in ToBassClass(). But isn't there a more elegant and efficient solution? abstract class BaseClass { B...

providing abstract class member variables from a subclass

What is the 'correct' way of providing a value in an abstract class from a concrete subclass? ie, should I do this: abstract class A { private string m_Value; protected A(string value) { m_Value = value; } public string Value { get { return m_Value; } } } class B : A { B() : this("string value...