abstract-class

'abstract class' versus 'normal class' for a reusable library

I'm developing a reusable library and have been creating abstract classes, so the client can then extend from these. QUESTION: Is there any reason in fact I should use an abstract class here as opposed to just a normal class? Note - Have already decided I do not want to use interfaces as I want to include actual default methods in ...

Workaround for abstract attributes in Java

In Scala I would write an abstract class with an abstract attribute path: abstract class Base { val path: String } class Sub extends Base { override val path = "/demo/" } Java doesn't know abstract attributes and I wonder what would be the best way to work around this limitation. My ideas: a) constructor parameter abs...

Abstract Base Class or Class?

For my semester project, my team and I are supposed to make a .jar file (library, not runnable) that contains a game development framework and demonstrate the concepts of OOP. Its supposed to be a FRAMEWORK and another team is supposed to use our framework and vice-versa. So I want to know how we should start. We thought of several appro...

How can this Ambient Context become null?

Can anyone help me explain how TimeProvider.Current can become null in the following class? public abstract class TimeProvider { private static TimeProvider current = DefaultTimeProvider.Instance; public static TimeProvider Current { get { return TimeProvider.current; } set { if (...

Question About Abstract Classes?

URL: Link (1) According to this wesbite .. you cannot implement Abstract classes but derive from them. This makes sense and I have read this many times. Like an interface, you cannot implement an instance of an abstract class, however you can implement methods, fields, and properties in the abstract class that can be used by the ch...

variables in abstract classes C++

I have an abstract class CommandPath, and a number of derived classes as below: class CommandPath { public: virtual CommandResponse handleCommand(std::string) = 0; virtual CommandResponse execute() = 0; virtual ~CommandPath() {} }; class GetTimeCommandPath : public CommandPath { int stage; public: ...

Why is an interface or an abstract class useful? (or for what?)

So my question is, why to use interfaces or abstract classes? Why are they useful, and for what? Where can i use them intelligently? ...

What am I not getting about this abstract class implementation?

PREFACE: I'm relatively inexperienced in C++ so this very well could be a Day 1 n00b question. I'm working on something whose long term goal is to be portable across multiple operating systems. I have the following files: Utilities.h #include <string> class Utilities { public: Utilities() { }; virtual ~Utilities() { }; v...

MyClassBase or BaseMyClass?

Possible Duplicates: Using Base in a Class Name C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass Naming Conventions for Abstract Classes What is the better way to name base abstract classes? I still can't decide where to put 'Base' word. Should it be 'BaseMyClass' or 'MyClassBase'? How do you name...

returning an abstract class from a function

Is it possible to return an abstract class(class itself or a reference, doesn't matter) from a function? ...

Python 2.6, 3 abstract base class misunderstanding

I'm not seeing what I expect when I use ABCMeta and abstractmethod. This works fine in python3: from abc import ABCMeta, abstractmethod class Super(metaclass=ABCMeta): @abstractmethod def method(self): pass a = Super() TypeError: Can't instantiate abstract class Super ... And in 2.6: class Super(): __metaclass_...

Use of Java [Interfaces / Abstract classes]

Hello, Lately i decided to take a look at Java so i am still pretty new to it and also to the approach of OO programming, so i wanted to get some things straight before learning more, (i guess it's never to soon to start with good practices). I am programming a little 2D game for now but i think my question applies to any non trivial p...

Create a new instance in a static function of an abstract class

abstract class db_table { static function get_all_rows() { ... while(...) { $rows[] = new self(); ... } return $rows; } } class user extends db_table { } $rows = user::get_all_rows(); I want to create instances of a class from a static method defined in the abstract pa...

Help with abstract class in Java with private variable of type List<E>

Hi, It's been two years since I last coded something in Java so my coding skills are bit rusty. I need to save data (an user profile) in different data structures, ArrayList and LinkedList, and they both come from List. I want to avoid code duplication where I can and I also want to follow good Java practices. For that, I'm trying to ...

How to initialize List<E> in empty class constructor?

Hi, The following code obviously doesn't work because List<E> is abstract: public class MyList { private List<E> list; public MyList() { this.list = new List<E>(); } } How can I initialize MyList class with an empty constructor if I need the list variable to be a LinkedList or a ArrayList depending on my needs? ...

C++ How do I give a member variable in an abstract class a default value?

In the header, I'm defining bool isActive. In classes derived from this one, I would like to make isActive false by default. I tried doing this by adding AbstractClass::isActive = false; to the cpp file, but that causes the error "Expected constructor, destructor, or type conversion before '=' token." ...

How to implement a unit converter in java

How could I possibly implement a unit converter in Java??? I was thinking of having a abstract base class: public abstract class Unit { ... public void convertTo(Unit unit); } Then having each class like Meter Kilometer Inch Centimeter Millimeter ... derive from that base Unit class. All the units of length would be in a pack...

Multiple generic types in one container

I was looking at the answer of this question regarding multiple generic types in one container and I can't really get it to work: the properties of the Metadata class are not visible, since the abstract class doesn't have them. Here is a slightly modified version of the code in the original question: public abstract class Metadata { } ...

C++: Create abstract class with abstract method and override the method in a subclass

Hi, How to create in C++ an abstract class with some abstract methods that I want to override in a subclass? How should the .h file look? Is there a .cpp, if so how should it look? In Java it would look like this: abstract class GameObject { public abstract void update(); public abstract void paint(Graphics g); } class Player...

What's a common practice of completing abstract class?

You have a class, that perfectly fits to be an abstract, but this class cannot work normally without data supplied from derived class. It's not convenient to pass all data to constructor because not all of it may be needed, and many of them can be dynamic (result from child function). What are the best practices to compose such structur...