你如何解决 command强指挥的问题。 你们是否为每个指挥部门单独设置一个类别? 还是有另一种方式(没有大量班级)?
请注意,在行动文本3上我面临问题。
www.un.org/Depts/DGACM/index_french.htm
事先感谢你!
你如何解决 command强指挥的问题。 你们是否为每个指挥部门单独设置一个类别? 还是有另一种方式(没有大量班级)?
请注意,在行动文本3上我面临问题。
www.un.org/Depts/DGACM/index_french.htm
事先感谢你!
指挥模式完全是为了将三个不同类别物体之间的关切分开:
Which, as wvxvw pointed out, usually means that you have a TON of classes that implement ICommand
that really just work as proxies to call methods on a Receiver -- which is required for Java. This can get a little unmanageable over time.
但是,请看一下某些法典,Im将遵循介绍指挥模式基本原理的样本代码,网址是:here,但稍加简化:
首先是
// Receiver
public interface IStarShip {
function engage():void;
function makeItSo():void;
function selfDestruct():void;
}
public class Enterprise implements IStarShip {
public function Enterprise() { }
public function engage():void {
trace(this, "Engaging");
}
public function makeItSo():void {
trace(this, "Making it so");
}
public function selfDestruct():void {
trace(this, "Self Destructing");
}
}
援引人:
// invoker
public class CaptPicard {
private var _command:ICommand;
public function CaptPicard() { }
public function set command(cmd:ICommand):void {
this._command = cmd;
}
public function issueCommand():void {
}
}
最后,一些指挥官:
// command
public interface ICommand {
function execute():void;
}
public class EngageCommand implements ICommand
{
private var receiver:IStarShip
public function EngageCommand(receiver:IStarShip) {
this.receiver = receiver;
}
public function execute():void {
receiver.engage();
}
}
public class SelfDestructCommand implements ICommand
{
private var receiver:IStarShip
public function SelfDestructCommand(receiver:IStarShip) {
this.receiver = receiver;
}
public function execute():void {
receiver.selfDestruct();
}
}
public class MakeItSoCommand implements ICommand
{
private var receiver:IStarShip
public function MakeItSoCommand(receiver:IStarShip) {
this.receiver = receiver;
}
public function execute():void {
receiver.makeItSo();
}
}
我们可以避开这些话:
var enterprise:Enterprise = new Enterprise;
var picard:CaptPicard = new CaptPicard();
picard.command = new SelfDestructCommand(enterprise);
picard.issueCommand();
迄今为止,它相当密切地遵循了示范守则,是《行动宪章》中指挥模式的相当标准的执行。 但是,现在我们有三条<代码>ICommand执行,而且作为回报可以增加的物品数目,也需要多少指挥才能确定模式。
如果我们开始审查指挥部本身,它除了告诉接收者做一些工作外,实际上没有做很多工作。 正如休夫休夫所暗示的那样,行动方已设有这样的设施:一等功能。
让我们看看一下可能实施这些措施的情况,以减少执行《公约》的次数,而你们需要绕过,而根本不改变你们的模式。
让我们说,我们采取了一种通用的指挥方式,可以说:
public class GenericCommand implements ICommand {
private var worker:Function;
public function GenericCommand(worker:Function) {
this.worker = worker;
}
public function execute():void {
this.worker.call();
}
}
Notice that our new type still implements ICommand
, but instead of being bound directly to some implementation, it accepts a worker to do some work on. It doesn t execute it right away, it just holds on to it and waits for something else to put it in motion.
然后,我们可以把我们的法典变成这样的东西:
var enterprise:Enterprise = new Enterprise;
var picard:CaptPicard = new CaptPicard();
picard.command = new GenericCommand(function() { enterprise.selfDestruct(); });
picard.issueCommand();
picard.command = new GenericCommand(function() { enterprise.engage(); });
picard.issueCommand();
picard.command = new GenericCommand(function() { enterprise.makeItSo(); });
picard.issueCommand();
有了这一条<代码>GenericCommand,我们就可以将所有指挥系统投入到这一新的格局中(或两者的组合和匹配)。
但是,如果你看上去,你就可以看到,通过提及封闭式代号<<>企业/代码>,我们正通过采用这一方法,将通用指挥权与IStarShip合并起来,而如果我们不小心谨慎,我们就可能会造成这种封锁的
我们可以把这个层面分开,使之更具活力。 而不是直接对当地变量进行封闭<代码> 企业代码>。 我们可以使用工厂模式,帮助我们积极掌握飞机。 考虑:
public class StarShipCommandFactory {
private var worker:Function;
public function StarShipCommandFactory(worker:Function) {
this.worker = worker;
}
public function to(receiver:IStarShip):ICommand {
return new GenericCommand(function() {
worker.call(undefined, receiver);
});
}
}
然后,我们可以利用这一方法创建“
var enterpriseA:Enterprise = new Enterprise();
var enterpriseB:Enterprise = new Enterprise();
var picard:CaptPicard = new CaptPicard();
var selfDestuctor:StarShipCommandFactory = new StarShipCommandFactory(function(starShip:IStarShip):void {
starShip.selfDestruct();
} );
var blowUpA:ICommand = selfDestructor.to(enterpriseA);
var blowUpB:ICommand = selfDestructor.to(enterpriseB);
picard.command = blowUpA;
picard.issueCommand();
picard.command = blowUpB;
picard.issueCommand();
这将减少你需要生成的静态类别数量,以利于使用头等功能的有活力的物体,但仍然适用相同的一般设想。
事实上,根据这种模式,你可以建立非常复杂的指挥系统,代之以对多个接收者采取多重行动,这可能是一个非常强大的东西。
ICommand
then?遵守传统模式的最大原因之一是在序列化方面放松。 由于这些物体是明确的,因此很容易将其序列化。 因此,请允许我说,您的代码为
如果你担心维持大量<代码> ICommands thatmap to receiver actions, 然后,我过去曾用美术方案解决这一问题。 利用废墟/平线,整理一系列档案,并自动生成<代码>ICommand绘图。 它们是大部分时间,相当宽松的执行,是自动化的主要候选人。
无论如何,这些都是我对这个问题的想法。 你可以做很多事情来帮助简化你的法典——我刚刚把地表rat。 你的微笑可能有所不同——回顾:“解决你的问题的模式,而不是解决问题的另一种方式”,但也许你可以从中看到一些有用的信息。
Command pattern is a coverup for Java s lack of higher order functions (inability to pass references to functions around). There s no point in using this pattern in AS / other ES languages because this problem doesn t exist there.
很不幸的是,这些天,学术界利用Java参加欧安会的研究,特别是如果欧安会是你的主要人物的话。 这将解释这一点和被移植到其他语言的 Java语,以及任何重要分析。
I use one class per comm以及. A multitude of classes is a small price to pay for the flexibility the pattern offers for certain problem domains.
利用游戏例子,有一个称为“猎物”的习俗类别——角色、敌人等——我开始界定指挥接口
IComm以及{
function execute():void;
}
每一指挥级对安装在施工器上的接收器实施执行方法:
public class GoRight implements IComm以及{
_gameEntity:GameEntity
public function GoRight(entity:GameEntity){
_gameEntity = entity;
}
public function execute():void{
_gameEntity.x++;
}
}
以及
public class GoLeft implements IComm以及{
_gameEntity:GameEntity
public function GoLeft(entity:GameEntity){
_gameEntity = entity;
}
public function execute():void{
_gameEntity.x--;
}
}
以及 so on for every comm以及.
If you use a stack where one comm以及 is called after the other finishes you need to add eventlisteners to listen to comm以及 completion as a trigger to start the next.
However IMHO if you find yourself building a piece of software where the comm以及 pattern becomes a key architectural solution I would think hard about whether actionscript or rather the Flash player is really the right tool. For task queuing 以及 do/undo of long comm以及 chains, concurrency - something Flash doesn t offer - becomes important for a good user experience. That s just my opinion of course...
I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?
So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...
I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...
Here [Ed. warning: full screen flash site with music]
I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...
I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...