| Author |
Multiple Inheritance
|
tarun saha
Greenhorn
Joined: Mar 23, 2010
Posts: 27
|
|
hi guys,
I have read many docs regarding multiple inheritance in java.
I know that in java one class can extend only one class but can implement many interfaces, but still my doubt remains unclear.
If i have 3 classes
public class MyClassA{
}
public class MyClassB{
}
public class MyClassC{
}
how can inherit the properties of the 3 classes. I read that multiple interfaces can be implemented. But interface cannot extend a class. So how will interface use the properties of class?
Lets say that my main intented class is
public class AllClassProperties which will have certain selected properties same as the three( i am not saying common properties, it is only selected properties and their methods)
how can i bridge between AllClassProperties and the three myclasses?
CAN WE USE INTERFACE INSIDE A CLASS?
please help me with a complete example or a link if you can...
thanks for any help in advance.
|
 |
Istvan Kovacs
Ranch Hand
Joined: May 06, 2010
Posts: 100
|
|
You could create interfaces for each of those classes (InterfaceA for MyClassA etc.), and have
Eclipse has support for delegation (Source -> Generate Delegate Methods).
If you search for composition inheritance, you'll find many articles, e.g.
http://www.artima.com/lejava/articles/designprinciples4.html
|
 |
tarun saha
Greenhorn
Joined: Mar 23, 2010
Posts: 27
|
|
|
hmm, i'l try it out.
|
 |
Istvan Kovacs
Ranch Hand
Joined: May 06, 2010
Posts: 100
|
|
tarun saha wrote:hmm, i'l try it out.
In general, try not to create classes that are overcomplicated. Implementing several interfaces will bring lots of public functions; the delegate methods will mean lots of code (even though generated). Check whether you can simplify the design, whether there's no way to avoid this class taking on so much functionality/responsibility.
|
 |
 |
|
|
subject: Multiple Inheritance
|
|
|