• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need explanantion on Design Pattern Mock Question 6

 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

Please refer to question 6 of Design Pattern mock
head first couldnt convince why they selected Transfer Object as the answer.

i choose - Intercepting filter beacause the question talks about reducing the number of requests

but head first says - Transfer Object because the question talks of gain in perfarmace in data access

Please clarify.

Thanks in advance !
 
David Bates
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what way do you think the Intercepting filter reduces the number of requests? The Intercepting filter pattern is applied to requests coming in from the client browser into the web server - you can't change the number of these requests (apart from asking users to stop visiting your website).

Once the server receives the request the controller will build a JSP view to return to the user. However, if that JSP page contains references to a remote EJB, a separate call will have to be made from the web container to the EJB container each time a method is called. For example, if "currentUser" refers to a remote object, the following snippet would cause *three* separate calls to the EJB container:

Current user is ${currentUser.name} who last logged in on ${currentUser.lastLogin} and has visited this site ${currentUser.numberOfVisits} times.

However, if you use the Transfer Object pattern you send back a simple Java object (POJO), rather than a reference to a remote object. This reduces the number of remote calls from 3 to 1, resulting in a performance gain.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi David,

It was so nice of you to explain it in such a lucid language.But i think you forgot to past the code snippet.

From what you said, this is my understamding

If we use the Transfer Object pattern the we will get a POJO called 'CurrentUser'. This will act as a Bean for the view to access. The bean will contain thre fields 'name,'lastLogin', 'numberOfVisits' and their values. So the only network trip that will ocurr when we get the 'CurrentUser' transfer object.

Is that fine ? I think it is.

Thanks a lot.

Niranjan.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi David,

It was so nice of you to explain it in such a lucid language.But i think you forgot to past the code snippet.

From what you said, this is my understamding

If we use the Transfer Object pattern the we will get a POJO called 'CurrentUser'. This will act as a Bean for the view to access. The bean will contain thre fields 'name,'lastLogin', 'numberOfVisits' and their values. So the only network trip that will ocurr when we get the 'CurrentUser' transfer object.

Is that fine ? I think it is.

Thanks a lot.

Niranjan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic