[Tutor] When to use classes

Alan Gauld alan.gauld at yahoo.co.uk
Sat Aug 19 14:26:56 EDT 2017


On 19/08/17 17:00, boB Stepp wrote:

> I try to keep this in mind.  Another thing I'm currently struggling
> with is when to use inheritance vs. separate, independent classes.

The golden rule is if the child is not a kind-of the parent then
it should be delegation not inheritance. Never use inheritance as
a mechanism for construction, its for specializing types.

Another anti-pattern to look out for is if you are adding a lot
of new methods rather than overriding inherited methods there's
a good chance you are going the wrong way.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list