abstract-class

Should an abstract class have at least one abstract method?

Is it necessary for an abstract class to have at least one abstract method? ...

What is the purpose of abstract classes?

I am trying to learn OOP in PHP, and I have some confusion about interfaces and abstract classes. They both contain no implementations, only definitions, and should be implemented through their sub-classes. What part of abstract classes clearly distinguishes them from interfaces? Also, due to their apparent similarities, based on what re...

Accessing class constant from abstract method in PHP5

Hey guys, I'm trying to get the value of a constant of an extending class, but in a method of the abstract class. Like this: abstract class Foo { public function method() { echo self::constant; } } class Bar extends Foo { const constant = "I am a constant"; } $bar = new Bar(); ...

Abstract constructor in C#

Why I can't declare abstract an constructor of my class like this: public abstract class MyClass { public abstract MyClass(int param); } ...

internal abstract methods. Why would anyone have them ?

I was doing some code review today and came across an old code written by some developer. It goes something like this public abstract class BaseControl { internal abstract void DoSomething(); } If you have a derived class within the same assembly, it would work public class DerivedControl : BaseControl { ...

Can I make interfaces or abstract classes in C# that declare methods with a parameter of unknown type?

I'm parsing a http GET query string into its components. In trying to make it modular (the number and types of parameters can vary quite a bit), I want to have a Parameter abstract base class or interface that defines whether a property has been set or not, along with a Set method that sets the value. Is there a way to do that with a var...

Are abstract class constructors not implicitly called when a derived class is instantiated?

Take this example: abstract class Base { function __construct() { echo 'Base __construct<br/>'; } } class Child extends Base { function __construct() { echo 'Child __construct<br/>'; } } $c = new Child(); Coming from a C# background, I expect the output to be Base __construct Child __construct...

Using abstract classes and Interfaces

If I have three classes class A class B extends A class C extends A Would using abstract classes or interfaces give me any type of errors or affect the way I implement the program? ...

Force a subclass to implement abstract subclass

I want to create an abstract class in java that forces all its subclasses to implement a SwingWorker (plus the SwingWorker's abstract doInBackground() and done()). In AbstractClass - abstract class Task extends SwingWorker<Void, Void>{}; I would expect this to cause the compiler to throw an exception when an extended class doesn't im...

Inheriting both abstract class and class implementation in C++

I hope this is a simple question. Can I inherit both an abstract class and it's implementation? That is, can the following be made to work? class A { virtual void func1() = 0; } class B { void func1() { /* implementation here */ } } class C : public A, public B { } I've tried a few variations, and am getting compile errors...

Why make Abstract classes and Interfaces?

Well I was going to ask what the difference is but it's been answered before. But now I'm asking why did they make these differences? (I'm speaking about java here, I don't know if the same applies to other languages) The two things seem very similar. Abstract classes can define a method body whilst interfaces can't, but multiple interf...

Can I omit interface methods in abstract classes in C#?

I'm a Java developer who's trying to move into C#, and I'm trying to find a nice equivalent to some Java code. In Java, I can do this: public interface MyInterface { public void theMethod(); } public abstract class MyAbstractClass implements MyInterface { /* No interface implementation, because it's abstract */ } public class ...

Abstract Class and Interface, Object Oriented Programming question

Hi there, I have a clue about Object Oriented Programming: I need to have a parent class HandlerException which needs to define the sign of three methods (MethodA, MethodB, MethodC). Then, I have a child class BusinessHandler which inherits from HandlerException and defines ONLY the MethodA of its parent class. Then, I have a child c...

Zend_Db_Table_Row_Abstract returns NULL -- PHP pukes

My apologies up front for being a) a newbie and b) almost certainly not giving enough info. So I have app that uses ZF to fetch data from MySQL and display it to the user. The user can select a row of data and fetch additional information (username, hostname, etc...). I'm having an issue with PHP puking when ZF returns null data from ...

Asp.Net MVC 2 DefaultModelBinder error using abstract classes

I have a simple Poco-Model using abstract classes, and it seems not to work with the Default ModelBinder of Asp.net MVC 2. One Item has several Objects in a collection, all using the same abstract base class. Model: public partial class Item { public virtual ICollection<Core.Object> Objects { get ...

abstract class NumberFormat - very confused about getInstance()

Hi, I'm new to Java and I have a beginner question: NumberFormat is an abstract class and so I assume I can't make an instance of it. But there is a public static (factory?) method getInstance() that allow me to do NumberFormat nf = NumberFormat.getInstance(); I'm quite confuse. I'll be glad if someone could give me hints on: ...

How can I assure a class to have a static property by using interface or abstract?

Hi, I have one abstract class -let's say myBase. And I want all the classes derived from myBase to have one static field called public static List<string> MyPArameterNames { get {return _myParameterNames;} } So, every child class can tell what parameter names it uses; I want static because I do not want to create an instance just ...

Abstract Methods in "Product" - Factory Method C#

I have a simple class library (COM+ service) written in C# to consume 5 web services: Add, Minus, Divide, Multiply and Compare. I've created the abstract product and abstract factory classes. The abstract product named WS's code: public abstract class WS { public abstract double Calculate(double a, double b); public abstrac...

Abstract base class puzzle

In my class design I ran into the following problem: class MyData { int foo; }; class AbstraktA { public: virtual void A() = 0; }; class AbstraktB : public AbstraktA { public: virtual void B() = 0; }; template<class T> class ImplA : public AbstraktA { public: void A(){ cout << "ImplA A()"; } }; class ImplB ...

How can I implement an abstract singleton class in Java?

Here is my sample abstract singleton class: public abstract class A { protected static A instance; public static A getInstance() { return instance; } //...rest of my abstract methods... } And here is the concrete implementation: public class B extends A { private B() { } static { instance = new...