Re: Java and OOP
- From: RedGrittyBrick <RedGrittyBrick@xxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Jan 2009 09:59:26 +0000
soup_or_power@xxxxxxxxx wrote:
Suppose I have an API with a class called APIClass.
In my app, I define a class
public class MyAppClass extends JFrame {}
Now how do I inherit the APIClass without rewriting the APIClass say
as an interface?
Ideally the MyAppClass has to extend JFrame and implement APIInterface
as:
public class MyAppClass extends JFrame implements APIInterface {}
"Favor Composition over inheritance" - Joshua Bloch.
I'm no expert but I'll throw in my ¤0.02 worth anyway :-)
If APIClass *must* be subclassed for some reason, I'd have
public class MyAppClass extends APIClass {
private JFrame frame;
}
I've never encountered a case where JFrame *must* be extended rather than encapsulated (this doesn't mean that such cases don't exist, just that I can't think of one).
If MyAppClass subclassing APIClass is undesirable, maybe I'd have MyAppClass compose a subclass of APIClass, this leaves MyAppClass free to extend some other class (or not).
As I said, just my ¤0.02 worth.
--
RGB
.
- References:
- Java and OOP
- From: soup_or_power@xxxxxxxxx
- Re: Java and OOP
- From: Arne Vajhøj
- Re: Java and OOP
- From: soup_or_power@xxxxxxxxx
- Java and OOP
- Prev by Date: ALL TYPES ONLINE JOB,19000$/- & DOWNLOAD FREE SOFTWARE
- Next by Date: Re: Getting an arbitary date the *RIGHT* way
- Previous by thread: Re: Java and OOP
- Next by thread: Re: Java and OOP
- Index(es):
Relevant Pages
|