• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

parallel inheritance hierarchies

 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Warren Dew
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

As far as I can tell, the client in the bridge pattern is a complete abstraction. I don't see how it lets me share some, but not all, code between client & server.
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the common code (error check), you can check on either the client or the server (preferably). Why would you want to do both?
 
Warren Dew
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error checking was just one example, but....

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.
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Warren Dew
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic