Re: good name to dispatch events (naming convention)
- From: Patrick May <pjm@xxxxxxx>
- Date: Wed, 08 Oct 2008 08:44:26 -0400
puzzlecracker <ironsel2000@xxxxxxxxx> writes:
As mentioned before, Connection class handles the requests from
clients, sends them over to some broker, and then dispatches results/
acks to clients .
Thanks for the clarification. If I understand correctly, then, an
instance of the Connection class is instantiated on the server for each
socket connection?
This design violates the Open/Closed Principle. Whenever you
add a new event type, you'll have to modify Connection. You have a
couple of options. The first is to move the behavior from whatever
calls Connection to the events and replace your handler methods with
a generic handler:
private void processRequest(Request reest)
{
request.execute();
}
I dont have a generic type request for my delegates. Events have
different signatures, sometimes comprised of built-in types, that are
read off socket. Perhaps, I am not understanding your suggestion
here.
It was me not having a full understanding of your design. To be
clear, what you're reading off the socket is a stream consisting of the
event type followed by any required parameters?
Another alternative is to use the Chain of Responsibility
pattern to add behavior dynamically while keeping the event classes
relatively simple.
I don't see how the chain of responsibility pattern can be used here,
without making the design more complex and harder to expand. I
basically have one event type per each client service call. Hence
client subscribes to events, calls one of the services, and waits for
results
Assuming I've understood your design correctly, Chain of
Responsibility can be used similarly to how I implemented it here:
http://www.spe.com/Chain_of_Responsibility.html. In your particular
case, the Connection class would be responsible for managing the
socket. When new data arrives, the Connection class reads the event
type and passes it and the socket connection to a chain of handlers.
The handler for that type accepts responsibility and uses the socket
connection to read any additional data required. (Adding a default
error handler to the chain is a good idea.)
Handlers can be added and removed at any time. Either the
Connection class or a shared HandlerChain class can maintain the list.
The interface for the chain consists of three or four methods:
handleEvent, registerHandler, unregisterHandler, and possibly
updateHandler.
The Handler interface, implemented by all event handlers, exposes
only a handleEvent(Event,Socket) method.
This approach makes the system open for extension but closed to
modification, as recommended by the Open-Closed Principle. Each class
has one well-defined responsibility and new functionality can be easily
added without impacting existing, working, tested code.
Will this work in your environment?
Regards,
Patrick
------------------------------------------------------------------------
S P Engineering, Inc. | Large scale, mission-critical, distributed OO
| systems design and implementation.
pjm@xxxxxxx | (C++, Java, Common Lisp, Jini, middleware, SOA)
.
- References:
- good name to dispatch events (naming convention)
- From: puzzlecracker
- Re: good name to dispatch events (naming convention)
- From: Phlip
- Re: good name to dispatch events (naming convention)
- From: puzzlecracker
- Re: good name to dispatch events (naming convention)
- From: Patrick May
- Re: good name to dispatch events (naming convention)
- From: puzzlecracker
- good name to dispatch events (naming convention)
- Prev by Date: Re: good name to dispatch events (naming convention)
- Next by Date: Re: OOP, this NG and you. Where is everyone?
- Previous by thread: Re: good name to dispatch events (naming convention)
- Next by thread: Re: good name to dispatch events (naming convention)
- Index(es):
Relevant Pages
|