Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Require Explanation

 
Goutam Bhattacharjee
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
Please see the following questions. The answers are provided as well. I need some explanation why these answers are best suited for these questions, as I cannot find it out myself. If you feel the answers are incorrect, please tell what should the correct one be.

1. You need to create a custom class loader to implement custom security. Therefore, you need to create objects without knowing the class of the objects or how to create them. What design pattern would you use?

Options:
a. Abstract Factory
b. Factory
c. Builder
d. Prototype
e. Singleton

The answer is: Prototype
---------------------------------------------------------------------------

2. A website offer's the customers price comparisons on a variety of different products. Revenue is generated by click through sales when the customer has found the best price. You are in charge on converting the web-based solution over to appropriate J2EE technology. Which choce is the best?

a. JSP, Servlets
b. JSP, Servlets, EJBs
c. Applets, EJBs

Answer: a. JSP, Servlets

Thanks in advance.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Goutam,

About #1: I think the Prototype design pattern is the appropriate one here.

If we look at http://www.dofactory.com/Patterns/PatternPrototype.aspx the custom security class is, let's say, ConcretePrototype1. My understanding is that our objective is not to deal directly with ConcretePrototype1, so we deal with an interface for it, which is the prototype class.

Regards,
Dan
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a nice presentation of the Prototype pattern:

http://trese.cs.utwente.nl/courses/university_courses/patterns/material/prototype.pdf

Our question states:

Therefore, you need to create objects without knowing the class of the objects or how to create them.


And that's exactly what this the Prototype pattern does well, as the presentation's fifth feature on page #8 says:

Configuring an application with classes dynamically.


Regards,
Dan
 
D. Rose
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q.1 - Yes, it answer is prototype as we need to load objects without knowing their class. Follwoing is GOF explanation


Configuring an application with classes dynamically.
  • [list]An application that wants to create instances of a dynamically loaded class won't be able to reference its constructor statically.


  • [list]Instead, the run-time environment creates an instance of each class automatically when it's loaded, and it registers the instance with a prototype manager.
  • [list]Then, the application can ask the prototype manager for instances of newly loaded classes.


  • [/LIST]

    Q-2 JSP and Servlet is correct answer. System in consideration is only query based system and would not really need any J2EE services like transaction maagement , concurrency, security etc.
     
    Goutam Bhattacharjee
    Ranch Hand
    Posts: 44
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you both for your views. But how did you figure it out that transactions and concurrent access are not required in qs 2?
     
    D. Rose
    Ranch Hand
    Posts: 215
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Basically product is for price comparisons so only read only data.No updates.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic