Re: Java and OOP

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

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.