Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Custom interfaces and inheritance in PureMVC  (Read 11201 times)
citizen_conn
Newbie
*
Posts: 9


View Profile Email
« on: January 08, 2010, 02:03:10 »

My scenario is the following:

I am extending Mediator with PageMediator.
I am implementing PageMediator with IPageMediator.
IPageMediator extends IMediator.

I dont understand 2 things:

1. If I add a public method to IPageMediator which is not implemented in PageMediator, the compiler warns me, however, if I include a public method to PageMediator which is not declared in IPageMediator, there are no warnings at all.

2. All concrete classes that extend PageMediator and that implement IPageMediator do not seem to need to contain any of the methods that are declared on IPageMediator and I can add as many public methods as I want even if they arent declared in IPageMediator.

Are these questions coming from a lack of understanding of interfaces and inheritance or is PureMVC structured in a way that would cause this behavior?

Thank you!
Logged
adrianw
Newbie
*
Posts: 8


View Profile Email
« Reply #1 on: January 08, 2010, 02:33:09 »

Hi,

1. A Class implementing interface HAS to implement all methods in that interface as public methods, however it may contain other methods, event if they aren't declared in the interface.

This means Your PageMediator has to implement all methods from IPageMediator(and also all method declared in IMediator because IPageMediator extends IMediator). Of course you can add any number of other methods to your PageMediator class.

2. If you extend PageMediator which implements IPageMediator, your concrete mediator also is PageMediator and IPageMediator, thats the rule of inheritance. Your concrete mediator inherits all public (it means also your interface methods because they are public) and protected methods.

Example:
If a USACitizen implements IEnglishSpeaker interface, it means you can be sure he can speak english, but he can also spean spanish or polish but you cannot call him ISpanishSpeaker or IPolishSpeaker because he didn't explicity tell you he does.

Hope this helps
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: January 08, 2010, 10:14:29 »

2. All concrete classes that extend PageMediator and that implement IPageMediator do not seem to need to contain any of the methods that are declared on IPageMediator and I can add as many public methods as I want even if they aren't declared in IPageMediator.
Adrian addressed both issues well, but the thing about #2 that you might still be missing is that the framework facade method retrieveMediator returns an IMediator. You're looking for a more specific interface (IPageMediator), so you have to cast if you want to access those methods:

Assuming there could be multiple page mediators registered:
:
var pageMediator:IPageMediator = facade.retrieveMediator(pageMediatorName) as IPageMediator;

-=Cliff>
Logged
citizen_conn
Newbie
*
Posts: 9


View Profile Email
« Reply #3 on: January 08, 2010, 10:53:02 »

Perfect. Thank you for clearing this up - it all makes perfect sense. And yeah Cliff thats what I will be doing exactly so thanks for the concrete example!
Logged
Pages: [1]
Print