Skip to main content

Basic question re extending classes

4 replies [Last post]
Joined: 2005-08-27

If I have a number of classes that all extend class A, and most of the code is in the class A, with only a few different setup routines in the extending classes:

is it best to do it this way,
or better to arrange to have only one instance of class A and have the other classes call methods in class A directly.

I don't know whether all the code in class A is repeated for each extending class.

It is a desktop application.

Any suggestions would be appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-08-02

well it depends ...

and when to subclass? when you think that the subclassed object has s "kind of" relationship to his superclass

Joined: 2005-08-27

I guess I didn't make myself clear.

It is a 'kind of' relationship.
But my question really is:
If I have two different subclasses B and C, of class A in the application, is the code from class A included with each of classes B and C, or is there one version of the code used by all subclasses.

I realize the variables have to be duplicated for each instance, and I assume that for multiple instances of a class the methods are only included once.
But are the methods from a superclass included for the subclasses.

Joined: 2006-09-01

A's code is in A. It is not copied into B and C.

Joined: 2005-08-27

> A's code is in A. It is not copied into B and C.

Answers my question completely.