Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command or Business Delegate over RMI

 
Chris Bicnal
Ranch Hand
Posts: 96
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm new to the JCD (and new to this forum, so hi! and have spent the past week thrashing out my design for my B&S assignment

While pondering England's depressing defeat yesterday evening (in the pub afterwards) I suddenly had an inspiration of brilliance regarding the command pattern.

My thinking here is that I could use the command pattern to encapsulate each request the client makes to the server therefore reducing the coupling between the two.

Now, if I was using sockets for my project I wouldn't hesitate in moving forward with this design - it saves having to worry about a protocol (too much anyway) and is easily implemented.

The question is though, is my original idea of defining an interface at the server end and adding a business delegate layer to control access to/from the server more suited to my RMI approach. (In other words, calling update, find, read etc... directly from the client). After all, with RMI I effectively have direct access to the client so I'm questioning whether the command pattern is trying to go against what RMI is all about or is it in fact a brilliant idea which affords easy future expansion/development, employs another buzz wordy pattern for my choices.txt and tidies up how my client and server interact.

I guess this could be seen as more of a general RMI 'best practise' question but one that I'd be interested to find people's views on.

I open it to the floor....
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11904
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

Welcome to JavaRanch and this forum.

Personally I think that the command pattern is not a very good fit for RMI. One of the major advantages of RMI is to make it appear to client programmer that a remote method is local. But when you add the command pattern you are stepping back from that direct access - to my mind this defeats the purpose.

Regards, Andrew
 
Chris Bicnal
Ranch Hand
Posts: 96
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was exactly my concern - the big question now is to justify using it over RMI, which I'm not so sure I can.

I like the some of the advantages the command pattern approach affords (especially regarding its simplicity, from a maintenance perspective and for future expansion) although I suspect I'm going to have to go with the sockets approach as, like you say, it goes against RMI's grain to restrict the remote call to one 'doIt' type method.

I'm now trying to think of dis-advantages of going down this route, although am struggling a little.....

*insert help below*
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11904
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

It sounds like you are trying to work out how to use the command design pattern in your solution, rather than working out a top level architecture and then deciding which patterns fit within it.

Personally I think this is dangerous - trying to force the use of a particular design pattern can result in awkward and/or hard to understand code.

If you really wanted to use the command design pattern in your application, you might want to look at whether it can be used for communication between the various components of an MVC (and, if you use the observer design pattern between the model and the view, you may find that it almost forces you to use the command design pattern - although that is not the only place in an MVC that can use the command design pattern).

Regards, Andrew
 
Chris Bicnal
Ranch Hand
Posts: 96
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,

Yeah, you're right. I need to take a step back, go back to the drawing board (not that I ever left it :-) and re-think my design.

I initially decided to use RMI, I was then considering changing that to use sockets to get the CP in there. I guess I've broken 'design rule' number one here.

Right then, where's that whiteboard.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic