oop - Java Multiple Inheritance -
In an attempt to understand completely how to solve many heritage problems of Java, I have a classic question that makes me clear should do.
Let's say that I have sub class I think this is the problem of classic diamond I was thinking that there is another way to solve this problem in which I can still make things for birds and horses. There was also a way to be able to make animals which would be very good but would not be necessary. You can create interfaces for animal classes (class in biological sense), such as and then and To reduce the duplicate code, you can create an abstract class that contains the general code of those animals that you want to apply. I want to add another extension. As, it opens the OP The only thing I knew was. However, I want to emphasize that I recommend bypassing the "multi-heritage" problem with the interface and I do not recommend using the interface which is already a solid Type (e.g. Bird) represents but more behavior (other people refer to duck-typing, which is also good, but I mean: biological class of birds, aviala). I also do not recommend using 'I' such as the interface names starting with birds and
horses in class
animal and I have a class
Pegasus is a bird and a horse from both
bird and
horses to
pegasus .
animal ,
bird and
horses creating class interfaces and
Pegasus from them
Public Interface Compound
P>
public class horse commissions {}
< Code> public class implementation of the Pegasus avialaya, Equity {}>
Linking to the plates:
Public abstract class AbstractHorse implemented Equidae {} Expansion of public square horse AbstractHorse {} Expansion of the public class poet's excellence Sarasher Aubiali {}
IBird , which just tells you why you do not need an interface. There is a difference for this question: Using the interface, build a heritage hierarchy, use useful sections, where necessary, where to apply solid sections and if possible, use the delegation.
Comments
Post a Comment