• Post Reply Bookmark Topic Watch Topic
  • New Topic

Looking for clarification on this: Object1 extends Object2<Object3>  RSS feed

 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The extends is not an issue.
The question really pertains to Object3 in the brackets.
Is this a way to have Object2 extend Object3 since multiple inheritances can't be done?

public class Object1 extends Object2<Object3>.....

Any insight on what the above declaration implies???
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just like you do
public class Object1 extends Object2

you simply need to do
public class Object2 extends Object3

Manish
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, Objects don't inherit other objects. Classes inherit classes

Secondly, I think I'm not following your question. Do you mean whether you can have



Yes, nothing in Java will stop you from doing that. However, I don't know why you would do that.

It's much more common to do this with interfaces when you build a Proxy pattern



Here MyInterface is the interface, and MyClass implements an interface. Proxy class wraps an object of type MyInterface(called delegate), and also extends MyInterface. When you call the method on the proxy, it calls doBefore, then the method on the delegate then do After. THis allows you to "inject" behavior by extending Proxy



This kind of design is very common
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are correct in that what is listed as Object3 is an interface.

public class A extends TableRowSorter<TableModel>......
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are probably seeing an implementation of either a Proxy pattern, or a decorator pattern. Both patterns are very common
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Landry wrote:Yes, you are correct in that what is listed as Object3 is an interface.
public class A extends TableRowSorter<TableModel>......

But there's absolutely nothing to stop you doing it for something more specific if you want, eg:
public class BitMap extends HashMap<Integer, Boolean> { ...

(purely for illustration, you understand; I'm not sure it's the best idea )

Jayesh's example is simply a common pattern.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!