2 superclass

Discussions about design and architecture principles, including native JADE systems and JADE interoperating with other technologies
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

2 superclass

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:35 am

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

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: 2 superclass

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:35 am

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.


Return to “Design and Architecture”

Who is online

Users browsing this forum: No registered users and 5 guests