Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Designing a class for inheritance

>>>Designing a class for inheritance places substantial limitations on the class.

I have not clearly understood this statement, concept.

Please advise. Any ideas, sugestions, sample code, links, resources highly appreciated. thanks in advan
0
gudii9
Asked:
gudii9
3 Solutions
 
for_yanCommented:

If you want to know the answer to that question,
read pages 88-91 from this book (hope you'll see them freely - at least they show up for me):

http://books.google.com/books?id=ka2VUBqHiWkC&pg=PA91&lpg=PA91&dq=Designing+a+class+for+inheritance+places+substantial+limitations+on+the+class&source=bl&ots=yYCiPlv2R1&sig=_MhdZ-qriZAdAeN94od7iY0ql0A&hl=en&ei=-xS2TZjJHOmV0QHaqIjWDw&sa=X&oi=book_result&ct=result&resnum=1&sqi=2&ved=0CBYQ6AEwAA#v=onepage&q=Designing%20a%20class%20for%20inheritance%20places%20substantial%20limitations%20on%20the%20class&f=false

They decribe in detail what you should and should not do if you are writing the class which
other programmers are supposed to subclass.

This of course implies rather big projects where you are creating the code which will be used by wide range of programmers, say
when you are writing some public libraries.
If you are writing a short program for yourself, you may be less concerned with such issues.


0
 
dpearsonCommented:
The basic idea is that if you write a class that is NOT designed for inheritance, you are free to change the internal workings of the class at any time.  Any data or methods that are not public can be changed and any user of the class won't know the difference.

However if the class IS designed to support inheritance, there's a much tighter relationship between it and any classes derived from it.  We like to say it's much more "tightly coupled".  This means it's much harder to design the class correctly in the first place as a lot more of the details of the class will affect how the subclasses will behave.  If you make a mistake in the original design, you may not be able to correct it later - so as the quote says there are a lot more limitations on the design of the class, than for one where the class won't be inherited.  You're not as free in the design of the class as you would be if nothing would derive from it.

Doug
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gudii9Author Commented:
>>>Designing a class for inheritance places substantial limitations

do they mean

>>>Designing a class for subclassing (by extends not implements by inheritance) places substantial limitations

>>>However if the class IS designed to support inheritance, there's a much tighter relationship between it and any classes derived from it.  We like to say it's much more "tightly coupled".

Inheritance supposed to avoid tighter relationship/coupling right than subclassing. please advise
0
 
for_yanCommented:
No, designing for inheritance and designing for subclassing is the same thing
Thoese are just different terms but mean the same - if you are writing the class, which you believe
at some point other people will want to write class which will extend your class (inherit from your class, subclass your class-
all the same terms) , then youn want
to follow these recommendations/guidelines.
It is all the same - "the class which supports inheritance" still the same meaning - you believe, that someone will want
to write another class which extends your class, then follow the above discussed points
0
 
objectsCommented:
java supports inheritence through subclassing
ie. to inherit a classes behaviour you subclass it
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now