× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: HTML to XML, vice versa
  • From: "Fred Kulack" <kulack@xxxxxxxxxx>
  • Date: Mon, 19 Mar 2001 21:18:19 -0600
  • Importance: Normal


Yeah, it is an often one of the things that people claim.

When doing inheritence, code reuse IS a great side effect and
a benefit, however, its only a _side effect_ and inheritence
should never be done for code reuse. Inheritence implies
the 'IS A' relationship between the object.

The problem comes in when someone does inheritence
simply to get code-reuse, that causes the subclass
to not only get the code, but to actually LOOK and ACT like
an object of the base class.

If you find yourself hiding much of the subclasses
behaviors, changing fundamentally how it acts, or
in general doing things that you 'feel' don't match
the type of object you inherited from, perhaps
you'd benefit from an inheritence model.

How about this for an example.
Lets implement a simple 'Bag' class.
We want to have the ability to do an addElement() and removeElement()
on the list, and have an underlying implementation manage
the fact that the list can grow and shrink.
In order to get code reuse, we 'extend Vector'

Whooops! We probably just REALLY screwed up our object model.
Now that our list is a Vector, people are doing elementAt(index) and
toArray()
on our list.
It behaves exactly like a vector, because it IS a vector.
In order to make it 'only' a list, we have to go in, and
override all the methods of Vector, and make them no-ops,
throw exceptions or some equally yucky thing.
Now. Is the end class we have a Vector?
Nope. It doesn't do vectorish things.
It looks like a vector thow, and extends the
Vector class.
MUCH better in this model (when we want code reuse)
to simply have our list class CONTAIN a vector and
implement some interface which provides ONLY
the addElement() and removeElement() methods.




>> On 03/19/2001 at 08:17:29 AM,
>> owner-java400-l@midrange.com wrote:
>> ......
>> Also, you start tending to use inheritence as a
>> mechanism for
>> code reuse, and that is a BAD use for inheritence.
>> Encapsulation should be used for that.
>> ......
>I always thought one of the often mentioned advantages
>of inheritance was to provide code reuse, whereby you
>put common code in the base class and override the
>code in the specializations.
>
>Am I missing something?
>
>Mike Hawes
>Categoric Software



__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---



+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.