Game Development Reference
In-Depth Information
The user interface code that executes this command is the following:
Command setColorCmd;
setColorCmd = factory.CreateCommand("SetColor");
setColorCmd.SetParam("OBJ_ID",object->GetId());
setColorCmd.SetParam("COLOR",COLOR_RED);
setColorCmd.Execute();
For the implementation, we can take advantage of the facilities of .NET lan-
guages like C# that are able to assign values to object properties knowing only their
names. This way, we will not have to implement the SetParam method specifically
for every single command in our system.
13.3.3 Practical Applications
Advantages for the development of the user interface. Development and main-
tenance of the user interface becomes more flexible as it does not depend on the
application logic. Many user interface development kits offer the possibility to ex-
tend the interface components with user properties that can be accessed in the form
editor. If we use one of these properties to save the name of the command, we can
configure an operation that is performed by a button, for example, without having
to touch a line of code.
It is also a lot easier to create different views of the same application; thus, the
user interfaces for artists and designers can be different.
Use in extensible systems. It is increasingly common to develop open systems
that can be extended with plugins or other mechanisms. Using a low-coupling
command system in this scenario has two beneficial effects:
1. Independent development between the host applications and the plugins is
easier because dependencies in source code are reduced, especially since the
need to know specific command types has been removed.
2. Any component of the system, either the host application or a plugin, can
invoke commands of any other component by knowing the name of the com-
mand to be run. Host-plugin interaction is the typical case of interaction in
this kind of architecture, but with this command system there is no restriction
foraplugintorunanoperationinanother(see Figure13.4 ) .
To make this possible, the command factory must be able to create commands
available in any component of the system. Again, the use of modern frameworks
like .NET makes our work easy because we can create instances of classes resident
in external modules with the class name and the assembly name that contains it.
In other cases, it may be necessary that each plugin implement and expose its own
Search WWH ::




Custom Search