aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Please help me to resolve this Design Pattern  question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Please help me to resolve this Design Pattern  question" Watch "Please help me to resolve this Design Pattern  question" New topic
Author

Please help me to resolve this Design Pattern question

ansh sh
Greenhorn

Joined: Jan 27, 2009
Posts: 4
Hi All,

I've done my SCJP and looking for SCWCD. I'm stuck in this question, can anyone please help me resolve this:

Currently a Web Application is receiving Requests in the form of HTTP Protocol
and serving its client. Chances are there for a totally new protocol to be introduced
in the future. Which of the following patterns can be used so that the introduction
of the new protocol doesn't affect the overall business logic of the system?

Options are:
a. Model-View-Controller
b. Service Locator
c. Business Delegate
d. Transfer Object
e. Intercepting Filter
f. None of the above

Waiting for your replies.....


Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Business delegate I guess.

If your whole front end is a web app, and then they don't use the web anymore, then you're done! But if all calls from the web app go through the business delegate, you can rip out the whole web/JSF/Servlets/Http/Struts or whatever, replace it with this new protocol what will replace http, and just make the same calls, from a different UI layer, through the Business Delegate.

Calls from the UI/client interface layer go through a business delegate to get to the data layer. If the UI/Client layer gets destroyed, the new UI/Client layer can still make calls to the business layer through the delegate. So, with this type of design, the UI layer is 'hosed', but no logic in the back end needs to change.

This new protocol is really going to mess alot of applications up.



-Cameron McKenzie
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
I think that the answer should be Model-View-Controller.

The reason for me to choose this answer is because the sentence in the question "Chances are there for a totally new protocol to be introduced in the future". When a new protocol introduced, you will probably have a new class somehow like NewProtocolServlet which extend GenericServlet (you are not going to use HttpServlet) , also for NewProtocolServletRequest class and NewProtocolServletResponse class. As we all know that the existing Controller which extends HttpServlet and having service() method with HttpServletRequest and HttpServletResponse arguments, so the changing of protocol is going to affect only the Controller.

Base on the above explanation, Service Locator, Business Delegate and Transfer Object will not be the choice because it is more towards hiding the model tier from web tier, which means any changes in model tier will not affect the web tier. For example, a local model object change to remote model object.

Why not Intercepting Filter ?
Intercepting Filter already using a more general class arguments in the doFilter() method which is ServletRequest and ServletResponse class, the only changes when protocol change is the code of casting ServletRequest and ServletResponse object to NewProtocolServletRequest object and NewProtocolServletResponse object before calling FilterChain.doFilter(). If you are using Intercepting Filter without MVC , where the business logic is all inside Servlets or JSP, a new protocol introduce will affect the code inside the service() method which consist of business logic.


SCJP 6, SCWCD 5, SCBCD 5
ansh sh
Greenhorn

Joined: Jan 27, 2009
Posts: 4
Thanks for the replies, Cameron and Lee...

Even I thought it would be MVC, but the changes should be made to even the controller, this put me in a dilemma . I feel the explanation which Cameron gave is good enough to support the Business Delegate pattern.

Please suggest any other approaches to find the solution of the problem....
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368


Currently a Web Application is receiving Requests in the form of HTTP Protocol
and serving its client. Chances are there for a totally new protocol to be introduced
in the future. Which of the following patterns can be used so that the introduction
of the new protocol doesn't affect the overall business logic of the system?

Options are:
a. Model-View-Controller
b. Service Locator
c. Business Delegate
d. Transfer Object
e. Intercepting Filter
f. None of the above


In this question they are asking about the affecting of business logic so I thing
Business Delegate
will be right choice.

Thanks,
Shailesh
Naveen Segu
Greenhorn

Joined: Apr 29, 2009
Posts: 6
Yes, I agree with Lee....


SCJP 1.5, SCWCD 1.5
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
If your whole front end is a web app, and then they don't use the web anymore, then you're done! But if all calls from the web app go through the business delegate, you can rip out the whole web/JSF/Servlets/Http/Struts or whatever, replace it with this new protocol what will replace http, and just make the same calls, from a different UI layer, through the Business Delegate.


Do you mean that you are not going to use Container ? ... trying to write all the listener, socket , network, security implementation for the current Web Application which is now using HTTP protocol, and writing a UI which go through Business Delegate ? I don't see any benefit for just only using Business Delegate here unless you mentioned that your new design of UI have another layer which can cater for any protocol.

Why not we just implement the existing interface provided in the API , and you only need to provide implementation for service() method (which most probably won't call those doGet()/doPost()/etc. method which relate to HTTP Method, since the question mention a new protocol). By doing this, the Container is still controlling the lifecycle of the servlet, and most probably the only thing you need to change is the Controller (i.e the Servlets)

Now comes to the point , Business Delegate is only an actor in between of Controller (receive the request and may/not return a response) and Model (business logic or entity), its life is to have a layer in between to avoid those code such as lookup and access (eg. direct POJO method invoke, JNDI, or RMI) to be exist in Controller which will causes tight coupling between Controller and Model. Therefore, back to the point, it is still the MVC which seperate the business logic and prevent it from being affected by any changes on the View or Controller.
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
Calls from the UI/client interface layer go through a business delegate to get to the data layer. If the UI/Client layer gets destroyed, the new UI/Client layer can still make calls to the business layer through the delegate. So, with this type of design, the UI layer is 'hosed', but no logic in the back end needs to change.


By doing this , you are actually using MV (without Controller), the Business Delegate as explained above is just to prevent the tight coupling for those lookup and access code. Whereas , the main thing which avoid the business logic being affected is still the design of MV (without Controller).


Hope my explanation is clear . If anything which you found incorrect, please point it out, I wish to learn from this discussion !!

Thank you !!
ansh sh
Greenhorn

Joined: Jan 27, 2009
Posts: 4

I understand your point,Lee. Thanks for that....

Now I'm completely clear with the solution..... Looking forward to learn more
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 687


Hi,


May be this will help you ....

Enterprise Design Pattern http://nishanpatel.wordpress.com/2009/04/17/designpatterns/



Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me to resolve this Design Pattern question