Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
July 26, 2017, 05:31:18 AM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: Where to define component constants?  (Read 3251 times)
4ucai
Jr. Member
**
Posts: 17


View Profile
« on: July 21, 2012, 04:39:37 AM »

Hi,

Consider this scenario:

Code:
public class Pattern extends MovieClip
{
public static const VERTICAL:String = 'vertical';
public static const HORIZONTAL:String = 'horizontal';
public static const DIAGONAL:String = 'diagonal';
public static const CORNER:String = 'corner';

public function Pattern()
{
stop();
}

public function setPattern(type:String):void
{
this.gotoAndPlay(type);
}
}

Somewhere in my code I have to send a notification:
Code:
sendNotification(ApplicationFacade.SET_PATTERN, 'diagonal');

Then mediator handles the notification:
Code:
public class PatternMediator extends Mediator
{
..

        override public function handleNotification( note:INotification ):void
        {
            switch ( note.getName() )
            {
case ApplicationFacade.SET_PATTERN:
var type:String = note.getBody() as String;
pattern.setPattern(type);
break;
            }
        }
}

Where should I put the constants(VERTICAL,HORIZONTAL,etc) for Patterns?

Should I put it in its Class? Mediator? or AppFacade? proxy?

Should I do this
Code:
sendNotification(ApplicationFacade.SET_PATTERN, 'diagonal')
or
Code:
sendNotification(ApplicationFacade.SET_PATTERN, Pattern.DIAGONAL)

Where should they belong? I don't want to have littered references. Soon, I will have to add another pmvc core which will also send notification for "SET_PATTERN", what is the best way for cores to have reference to this.

Thanks
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW
« Reply #1 on: July 21, 2012, 08:25:58 AM »

For my part, I always have a dedicated «abc» package (a Java common convention) where I put all those sort of  static classes. I create a NotificationNames, MediatorNames, ProxyNames static classes. This is the definitve solution for Dependency Injection and loose coupling.

In your case if the application has only one module where which a lot of classes will need the Pattern names, I would definitely create a PatternNames class and use it from «abc.PatternNames.VERTICAL» …
Logged
4ucai
Jr. Member
**
Posts: 17


View Profile
« Reply #2 on: July 21, 2012, 08:50:56 AM »

@Tekool

Thanks, for your comment. I'll give your suggestion a try.
Logged
Pages: [1]
Print
Jump to: