Can I hold any data members in abstract base class?

I have an abstract class:

type
  TInterfaceMethod = class abstract
  public
    destructor Destroy;         virtual; abstract;
    function GetBasePlan: Word; virtual; abstract;
    procedure CountBasePlan;    virtual; abstract;
    procedure Calculate;        virtual; abstract;
    procedure PrepareForWork;   virtual; abstract;
  end;

and a derived class:

type
  TFogelMethod = class(TInterfaceMethod)
  private
    matrix: TFogelMatrix;
    BasePlan: Word;
  public
    constructor Create(var matr: TFogelMatrix);
    procedure Calculate;
    function GetBasePlan: Word;
    procedure CountBasePlan;
    procedure PrepareForWork;
    destructor Destroy;
  end;

The question is, can I place the implementation of GetBasePlan and CountBasePlan methods into base class, make them only virtual - not abstract as now - and also place member BasePlan there? So, can I do this:

type
  TInterfaceMethod = class abstract
  private
   BasePlan: Word;
  public
    destructor Destroy;         virtual; abstract;
    function GetBasePlan: Word; virtual; 
    procedure CountBasePlan;    virtual; 
    procedure Calculate;        virtual; abstract;
    procedure PrepareForWork;   virtual; abstract;
  end;

In case I can do it, will it be good from the point of view of object-oriented design, and how can I exactly access this member from derived classes?

Answers


Yes you can. Abstract classes are classes and they can have implementations.

By adding the abstract keyword to a class, you prohibit the class to be instantiated. It does not require to have any abstract methods.

A class with absract methods can be instantiated, but this result in a warning at compile time and an exception if the method is called.

Interfaces have no implementation, they have to be implemented by classes (which can be abstract by the way).


Just to add to Gamecat's answer, not only can you, but you should put your common code there.


Need Your Help

Fancybox zindex on quicktime video player

jquery css video fancybox quicktime

I am tasked with creating a youtube like site. I have a fancybox that i am using to capture log in information. The problem I have is that when I pop up the fancybox It is placed behind my video p...