2 superclass
Posted: Fri Aug 07, 2009 11:35 am
by ConvertFromOldNGs
by adam >> Mon, 15 Sep 2008 12:16:25 GMT
Hi Jade support
during a desin class in Jade, I have a question ....
is it possible 1 sub class ha more than 2 superclass ?
( the second superclass is not superclass from first superclass )
Thanks for your explaination
Re: 2 superclass
Posted: Fri Aug 07, 2009 11:35 am
by ConvertFromOldNGs
by Dean Cooper >> Mon, 15 Sep 2008 14:20:23 GMT
No. By design, JADE does not support multiple inheritance.
If you need to do something like this, consider using Interfaces instead (from the Browse menu, select Interfaces to define an Interface; from the Classes menu, select Interface Mapping to implement an Interface on a Class). Please refer to Chapter 15 in the UserGuide.pdf manual.
Like interfaces in other languages, JADE interfaces let you define a set of methods that are guaranteed to be available on implementing classes, regardless of where those classes sit in the class hierarchy. So you could define two interfaces: one that specifies the behaviour of what you'd want to inherit from your first superclass; and another for your second superclass. By implementing both of these interfaces on your subclass, you can now pass any subclass instance to a method that operates on an interface type. That is, instead of having a method like this:
doSomething(obj : SubclassType);
your method looks like this:
doSomething(obj : InterfaceType);
This method can now operate on any object whose class implements the InterfaceType interface.
If you're wanting to have a common implementation of certain interface methods, consider putting these on a singleton transient object that all implementors can call (ie: individual interface method implementations can just delegate to the methods on the singleton object).
Dean.