× 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: Source Changes
  • From: "Larry Loen" <lwloen@xxxxxxxxxx>
  • Date: Wed, 30 May 2001 09:59:26 -0500
  • Importance: Normal


Rui Duarte asked:

>The (dis)/advantages between abstract classes and interfaces are not very
>clear for me, or when one/other should apply better.
>I am learning more of OO and Java.

Do not think of this as a matter of technique.  The point of O-O technology
is to try and make the world inside the computer match the real world a
little more closely.

The choice between an interface and a class is often the difference between
what the O-O world calls and "is a" relationship and a "contains"
relationship.  For most uses of Java, this is the right way to think about
it, especially for someone doing their own early designs.

It is easy to deal with this in familiar settings.

A beagle "is a" dog.
A tiger "is a" cat.

But, a "collar" is not a dog nor is a "collar" a cat.

Therefore, if you were in a circus and had a dog and a tiger, you might
have the following:

public class tiger extends cat implements collar {
}

public class beagle extends dog implements collar {
}

That should help you get started.  It is sometimes harder to see these
relationships in actual work, but taking the time to work this out is
really the important thing in an O-O design.  There is some added
confusion, of a sort, added by the fact that you can't define an interface
to have default methods nor define them to have data in the interface
description itself.  This is true even when every implementation of the
interface is likely to have the same or similar data within the actual
class that does the implementation.  However, this is another powerful clue
about when something should be an interface -- it is really about things
you need to do and not any specific "noun" or "object."

If you can apply the above to your problems, you will not ordinarily go
wrong.  While Javasoft defines many interfaces, they don't arise quite as
often in practical work, or at least they haven't in mine.


Larry W. Loen  -   Senior Java and iSeries Performance Analyst
                          Dept HP4, Rochester MN


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