2011-07-06 58 views
1

我试图在Flex RIA应用程序的Cairngorm微架构中建模类关系。我有点困惑。UML中的继承和依赖关系建模

例如,我有两个类FrontController和Controller。控制器扩展FrontController。另一方面,我有ICommand接口和实现ICommand的SaveEmployeeCommand。

FrontController有这两种方法...

public function addCommand(commandName : String, commandRef : Class, useWeakReference : Boolean = true) : void 
    { 
    if(commands[ commandName ] != null) 
     throw new CairngormError(CairngormMessageCodes.COMMAND_ALREADY_REGISTERED, commandName); 

    commands[ commandName ] = commandRef; 
    CairngormEventDispatcher.getInstance().addEventListener(commandName, executeCommand, false, 0, useWeakReference); 
    } 

/** 
    * Executes the command 
    */ 
    protected function executeCommand(event : CairngormEvent) : void 
    { 
    var commandToInitialise : Class = getCommand(event.type); 
    //#### THIS IS DEPENDENCY ON ICommand INTERFACE #### 
    var commandToExecute : ICommand = new commandToInitialise(); 

    commandToExecute.execute(event); 
    } 

控制器具有构造至极init()方法是这样的...

public function init():void 
{ 
    // SaveEmployeeEvent extends CairngormEvent 
    // SaveEmployeeCommand implements ICommand interface 
    //### THIS IS DEPENDENCY ON SaveEmployeeEvent AND SaveEmployeeCommand ### 
    addCommand(SaveEmployeeEvent.SAVE, SaveEmployeeCommand); 
} 

所以,让我们考虑只是依赖关系上的命令。如果我们看代码,我们将看到FrontController依赖于ICommand,并且Controller对SaveEmployeeCommand有某种依赖性。 我应该在UML类图上显示'Controllers-> Commands'依赖关系吗?(第一个依赖是FrontController-> ICommand,第二个是Controller-> SaveEmployeeCommand)
我的困惑是关于继承的一部分。如果我在FrontController和Controller之间放置继承关系,则意味着Controller也是FrontController,所以他也依赖于ICommand(依赖项通过addCommand方法继承)。我应该如何模拟这种情况?我提出了一些可能的解决方案的例子......任何建议?

Dependencies model

回答

0

您的图表中的关系看起来是正确的,除了刻板印象。我会改变FrontController和ICommand之间的依赖关系到<<Instantiate>>