Posted by: prankster February 18, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        
I dont think cyclic inheritence is supported in any language except for english.

Java doesnt support  multiple inhertiance, but it can be done by
src:http://csis.pace.edu/~bergin/patterns/multipleinheritance.html


General Multiple Inheritance

We can use the above to see how to provide general multiple inheritance. The difference here is that we may not be able to design one of the classes to be a mixin. In the usual case, the two classes are predefined and do not require services from each other. This means that the MRequires interface is not needed. However, we still need to define one interface, since Java won't let us mix two classes together.

If we do have the luxury of designing at least one of the classes then we can proceed as before, treating that class as the mixin and defining an interface that it will implement. Otherwise we need to do a bit more. Suppose that we would like to mix the class Parent of the previous section with a class Other defined below.

Class Other
{	public Other(int value) { ... }
	
	public void whatever()
	{...
	}
}

Since Java will let us extend only one class, we need to define an interface that declares the public features of the other. We will do this to make our life simple here, though you may choose to do the next step for the class of least importance and whose methods are going to be called least often. Here we will define an interface to give the public methods of the class Other.

Interface OtherInterface
{	void whatever();
}

We can now build a subclass of Other by doing nothing more than implementing this new interface and providing any required constructors (which are not inherited).

class OtherChild extends Other implements OtherInterface
{	public OtherChild (int value){ super(value); }
}

If we had the freedom to modify class Other we could avoid the class OtherChild and just have Other implement this new interface.

This new class is just like an Other, but it advertises that it implements the OtherInterface. From here we can proceed as in the mixin case by extending the Parent class, implementing he OtherInterface and creating a new OtherChild object to which we delegate the messages defined in the OtherInterface.

Class ParentChild extends Parent implements OtherInterface
{	public ParentChild(...) { child = new OtherChild(...); ... }

	public void whatever() { child.whatever(); }

	private final OtherInterface child;
}

So, in this class we have merged the actual implementations of two other classes, Parent and Other without modifying either class. This is general multiple inheritance. In Java we needed to define and implement interfaces and use delegation to an object of one of the classes to achieve this.

Conclusion

Multiple inheritance is needed only rarely. The fact that it is a bit awkward to achieve in Java is not a disadvantage as it may discourage you from using it in those cases in which a better solution is available. However, you should be aware that extensions to Java are not necessary to achieve the use of most features that Java seems to lack. Rather the Java was a good, sound, and complete language design that supports the kinds of things that developers need. It takes skill, however, to see how to achieve some of the less used idioms such as multiple inheritance.

Read Full Discussion Thread for this article