[Tutor] What are the benefits of template or abstract base classes?

Alan Gauld alan.gauld at btinternet.com
Mon Jun 8 20:12:26 EDT 2020


On 08/06/2020 19:00, boB Stepp wrote:

> I did receive the original email prior to it appearing on the Tutor Archive.

Glad it went somewhere. It certainly never showed up on the list!

> Hmm.  Then ABCs seem quite useful.  I wonder why I normally only see
> mention of them as being advanced features?  

I guess because the vast majority of folks using classes don't
really build OOP programs, they build procedural programs
that use classes and objects as "smart data". And thats how many
beginner tutorials (including mine) teach it.

But if you read some of the more advanced OOP and especially OOD
books/tutorials you will see a lot more on using ABC/virtual classes.
A good example of one such is Grady Booch's book.

> they would seem very useful for anything beyond small, simple OO
> programs.  

Definitely more useful when you get to something with, say,
double-digit number of classes. I'd say at least 4 or 5 to make much
sense of it.

> ...with mixins its normally a case
>> of partially implemented classes rather than pure abstracts
>>  - what C++ calls virtual classes.
> 
> So these concepts are language-agnostic and broadly used?

Absolutely. They are a fundamental part of the OOP paradigm.
Almost all OOD techniques work along the lines of:

0) identify requirements as a set of use cases and user stories
1) identify classes and responsibilities
2) identify is-a commonality between classes and represent
   generalized versions as ABC (Person, Shape, Network,
   Form, Request, transaction, etc)
3) create a high level framework solving the problem
   using only the ABCs. (include has-a and uses relationships)
4) build sufficient concrete classes to test the framework
   with 1 scenario/story
5) build more concrete classes, test another scenario or story.
6) repeat 5 until done.

-- 
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