Re: [Q] Inheritance, Composition and Abstract super classes
Re: [Q] Inheritance, Composition and Abstract super classes
- Subject: Re: [Q] Inheritance, Composition and Abstract super classes
- From: Joakim Danielson <email@hidden>
- Date: Mon, 24 May 2004 13:46:41 +0200
On 2004-05-24, at 02.52, Peter.Teeson wrote:
In the new Cocoa Document app I am designing I have a situation where
it seems to me better to use an "abstract" super class and inheritance
rather than composition (usually the better approach).
As a simple example of what I mean consider bookeeping:
Accounts Receivable and Accounts Payable both need to maintain contact
data on a company's address, phone, fax, ship to etc.
To me inheritance from an "abstract" super class makes sense for that
example. Then the child classes can add specific behaviours as
desired.
Now consider the MyDocument class as the "abstract" class and consider
two or three child classes inheriting from it.
My questions are:
(0) Should any of the MyDocument definitions of overridden methods be
commented out?
I'm not sure what you are saying here, but it sound like you want to
override all or most methods of myDocumnet's superclass. Assuming that
the superclass is NSObject or NSDocument I don't see why you should
override any method unless you really need to.
For me, the class NSObject (and Object in Java) is just the root class
that all other classes need to inherit from directly or indirectly.
That is a rule I have to follow in my code but something I never care
about when I design my classes. You should focus your design on the
attributes and methods that is important for the real world problem
(business case/use case) your class is needed for.
(1) If a method that is overridden in the MyDocument class is also
overriden in one of the child classes is my understanding correct that
it is the child class that receives the message and that the super
class method will NOT receive it unless explicitly invoked from the
child class?
That is correct.
Joakim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.