My teacher says that whenever we want to add new functionality to a class we should make a sub-class and implement there. Is this good pr…

This is just a bad example of reuse.
Reuse, in the OO paradigm (and LinkedList<T> is not OO code) would involve knowing the invariants of the base class, and reuse by inheritance would mean that you can strengthen that invariant. For instance a square is-a rectangle is a trapezoid. All have four straight sides, with ever increasing constraints placed.
A printable LinkedList may violate some invariant in an esoteric system, like "must work in an FPGA" where there may not be a display.  But I agree with others this a poor example, and ostream_iterators are what's needed here

Answer by Lance Diduck:

This is just a bad example of reuse.
Reuse, in the OO paradigm (and LinkedList<T> is not OO code) would involve knowing the invariants of the base class, and reuse by inheritance would mean that you can strengthen that invariant. For instance a square is-a rectangle is a trapezoid. All have four straight sides, with ever increasing constraints placed.
A printable LinkedList may violate some invariant in an esoteric system, like "must work in an FPGA" where there may not be a display.  But I agree with others this a poor example, and ostream_iterators are what's needed here

My teacher says that whenever we want to add new functionality to a class we should make a sub-class and implement there. Is this good pr…

Advertisements

Leave a comment

Filed under Life

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s