Example: Voting

Figure 5.4 presents the approach on a voting example. There is a "VotingSvc" interface which clearly defines the scope of services for voting domain (so called voting API). The interface is realized twice by two distinct implementations. The first one is "VotingSvcImpl", which provides the actual functional implementation of all the functions (operations) defined by the "VotingSvc" interface. An instance of "VotingSvcImpl" is created, initialized and stored in "ServiceMgr" which makes the service available to other interested components.

The second implementation is "VotingSvcHttpProxy", which serves as a client proxy, delegating all the requests to the appropriate server. This particular proxy uses HTTP as a communication protocol. Note, that this is one of many examples, one can use SOAP over HTTP, RMI, CORBA, plain TCP/IP, or whatever else.

The "VotingController" is used for dispatching the functions execution, when the generic "execute" operation is used, rather then the explicit ones, like: "getVotingQuestion", "vote", etc. This is used mainly on the server side, when the request transportation layer need to make calls to the actual service implementation.

Figure 5.4: Class Diagram: Service Implementation Example "Voting"

Figure 5.5 presents the service implementation abstraction technique using interaction diagram. It is demonstrated on execution of function "vote". The diagram demonstrates how the event execution gets propagated all the way towards the actual functional implementation at the very end --- the instance of "VotingSvcImpl".

The sequence begins by obtaining instance of local "ServiceMgr" which in turn returns instance of the requested service "VotingSvc". As already mentioned, the application developer does not know at this point, what is the actual implementation of the service interface nor he/she care about it. Once the "VotingSvc" is available, a service function can be called, in our case it is "vote". Since this "VotingSvc" implementation is the proxy --- "VotingSvcProxy" --- then the function call just gets propagated through Internet, "ServicesServlet" and again to "ServiceMgr". At this time, the implementation of the "VotingSvc", registered on this "ServiceMgr", is the actual functional implementation. Therefore, when the "ServicesController" calls the "vote" operation, the vote gets registered (which is the required service functionality) and appropriate response is returned to the client.

Figure 5.5: Interaction Diagram: Service execution propagation

What is noticeable on this diagram is: two distinct instances of "ServiceMgr" and two distinct instances of "VotingSvc" implementation. Each of them on either client and server.