Re: Interface complexity problem in game



Responding to Guild...

This paragraph suggests that 'world' represents another, largely undefined subsystem. In that case it is a subsystem interface.
Using the GoF Facade pattern is a common way to implement subsystem interfaces. While that Facade is a single class with a large number
of interface methods, it does not implement the functionality. It is simply a buffer class that re-dispatches the messages to the objects that implement the subsystem. So in that case a large number of
methods is acceptable. In fact, it is highly desirable because it
hides the implementation of the subsystem.


This is exactly what I am doing. I would be crazy to try to define something that I know will be vastly complicated without breaking it up into a large number of objects. Therefore, I will continue with confidence and much appreciation!

OK, but a couple of caveats. Facades should be simple. That is, they should not contain problem semantics in their implementations; they exist purely as a decoupling agent to hide detailed implementations. Ideally they simple redirect a message. However, that segues to the second caveat...


Subsystem interfaces should be pure data transfer interfaces (e.g., that's why event-based interfaces are popular for things like GUIs and RAD IDEs). That is, one just has {message id, data packet} where the data packet contains by-value data. The receiver uses the "message id" to determine how it should respond. In a Facade pattern the "message id" essentially becomes the Facade method name (e.g., the "doSomething" in your original post).

Note that in event-based processing one needs only one processEvent (event id, <data packet>) method in the interface. This is fundamentally equivalent to a bunch of processAnEvent (<data packet>) methods, which is why lots of methods in a Facade interface is not a problem.

The real key to decoupling, though, is that only by-value data is passed. The data packet may be implemented as an object (this is what DAO is about) but it exists only for the communication. That is, one does not pass objects across the subsystem boundary that are part of the subsystem implementation because that exposes the subsystem implementation.

Such interfaces come at the price of encode/decode of the data packet on each side. However, that will be more than offset by improved robustness due to the decoupling of the implementations (i.e., all each side needs to do is properly map the "message id" and the data packet in its own terms). Thus changes are much more likely to be restricted to one side because the data the other subsystem needs is unlikely to change (i.e., just the way it is selected for the encode is changed). (Data tends to be more stable than behavior when requirements change.)

--

*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions  -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
(888)OOA-PATH



.



Relevant Pages

  • Re: patterns for getting system status...
    ... subsystem interface. ... we provide a higher level sub-system with status that we ... If both the Client and the Devices are legacy systems, I think you may be in trouble if your Controller really has to make control decisions (as opposed to simply resolving syntactic mismatches between interfaces). ... they provide an output Facade interface that subsystem implementation objects talk to when they need to send messages to the outside world. ...
    (comp.software.patterns)
  • Re: Interface complexity problem in game
    ... <data packet>) method in the interface. ... one does not pass objects across the subsystem boundary that are ... the facade, but they may or may not be considered part of the subsystem ... creatures, and I let them interact through a facade so that I don't ...
    (comp.object)
  • Re: Exposing Business Layer Objects to Presentation Layer
    ... > those interfaces do the mapping of the data to their own paradigm. ... > (think: Facade pattern). ... > to the relevant objects that implement the subsystem. ... > layer view of things. ...
    (comp.lang.java.programmer)
  • Re: Exposing Business Layer Objects to Presentation Layer
    ... > those interfaces do the mapping of the data to their own paradigm. ... > (think: Facade pattern). ... > to the relevant objects that implement the subsystem. ... > layer view of things. ...
    (comp.object)
  • Re: Part 2; COM issues
    ... with the functionality of the object, you would have no visibility into ... > client code..and actually I do not believe that the infrastructure ... infrastructure were encapsulated in its own subsystem, ... interfaces. ...
    (comp.object)