I've got a situation where I have an inheritance hierarchy for commands on a client-server system. The commands are sent from the client to the server.
Associated with each command is some code the client application needs, some code the server application needs, and some code (such as error checking) that both need. However, for security reasons, I don't want the code that's needed only by the server to be compiled into the client.
What's the best inheritance hierarchy (or hierarchies) for this? I haven't yet been able to come up with one that doesn't require more classes than I feel ought to be required.
I think the bridge pattern would do it. Not only bridge decouples abstraction from its implementation, but also it decouples client from the server. Changes on the server would have no impact on the client. Thus, client does not need to recompile their code.
I want error checking on the server side so that unexpected bit messages - such as from a hacked client - are rejected cleanly rather than causing unexpected consequences. (For an example of what happens when you don't do this properly, just see the very frequent Windows worms.)
I also want the same error checking on the client side so that, when the user enters an unrecognized command, the client lets the user know immediately rather than just failing unexpectedly when the server rejects the message.
If you want to do it that way, you'll need to either share the common code between clients and a server or distribute these code from the server to the clients (just like applet). You'll need to keep the clients' common code insyn whenever these code has been modified.
For any that are interested, I ended up using three separate hierarchies. The code the client needs for sending the commands is in one inheritance hierarchy in the client code base; the code the server needs for processing the commands is in another inheritance hierarchy in the server code base; and, the shared code is in a corresponding set of classes in the common code base. The shared code consists of static functions that can be called from either the client code or the server code.
This seems like a lot of classes, but at least it eliminates duplicated code.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop