× 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 11:09:35 -0600
  • Importance: Normal


On 03/19/2001 at 08:17:29 AM, owner-java400-l@midrange.com wrote:
How does this differ from what Fred explained?  Are there pros, cons, or
are
they the same?  When you say "subclass a class" I assume you mean to define
the one Formatter class, then for the XML and HTML classes, "extend" the
original formatter class.

The 'interface' and 'implements' is java's solution to the
evils of multiple inheritence.
I use interfaces and containment more frequently than
inheritence.

Abstract classes and abstract methods can get you in a jam,
because if you've got your class extending a class.
Since you can only extend ONE class (single inheritence), this
can get you into a design quandery sometimes.
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.


So, if you want to use some code from another class BASE and you
want your object to be an instance of that class, then restructure
into interfaces and use 'implements'.

/* Class that seems abstract but still does some useful stuff. */
class Base {
   public void foo() {
      // Method with useful logic
   }
   public abstract void bar();
   public abstract void bazzle();
}

class MyClass extends BASE {
  // I try to stay away from this.
}

/////// Instead, you can go this route.

interface Base {
   public void foo();
   public void bar();
   public void bazzle();
}

// A common programming model is to call
// this class 'BaseImpl'.
class BaseHelper {
   public void foo() {
      // Method with useful logic
   }
   // You COULD make this implement Base if
   // you wanted, but its really only intended
   // to provide help for a subset of the
   // behavior foo() provides and thus
   // DOESN'T logically implement Base.
   // We don't want to use inheritence or
   // implementation to do code reuse, so
   // we make sure it doesn't physically either,
}

class MyClass implements Base {
   BaseHelper  bh = new BaseHelper();

   public void foo() {
       bh.foo();
   }
   // As more stuff becomes factored out in
   // your multiple implementations of 'Base',
   // you may find that behavior from
   // those multiples migrate to BaseHelper
   // and are common.
   public void bar() {
      // implementation
   }
   public void bazzle() {
      // implementation
   }
}



"The stuff we call "software" is not like anything that human society
  is used to thinking about. Software is something like a machine, and
  something like mathematics, and something like language, and
  something like thought, and art, and information...
  but software is not in fact any of those other things."
Bruce Sterling - The Hacker Crackdown

Fred A. Kulack  -  AS/400e  Java and Java DB2 access, Jdbc, JTA, etc...
IBM in Rochester, MN  (Phone: 507.253.5982   T/L 553-5982)
mailto:kulack@us.ibm.com   Personal: mailto:kulack@bresnanlink.net
AOL Instant Messenger: Home:FKulack  Work:FKulackWrk

+---
| 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-Ups:

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.