aspose file tools*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Pattern used in the qn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Pattern used in the qn" Watch "Pattern used in the qn" New topic
Author

Pattern used in the qn

Subash Murugan
Greenhorn

Joined: Mar 26, 2008
Posts: 20
Hi Ranchers,

Am preparing for SCEA and happened to see the following qn in one site,

You are creating a web application for an online product ordering system. You have decided to use connection pooling to reduce load on the databases. Since you have many databases, you want to create one pool instance of the ConnectionPool class for each database. Depending on what is requested, you may have to connect to a variable number of databases. What pattern should you use?

a) Abstract factory b) Factory Method
c) Builder d) Prototype
e) Singleton

Where answer is given as E, and the reason given "The Singleton doesn't just create a single instance it can also be used to create a variable number of instances of a class. "
Am just wondering its given correctly or not? can someone please clarify?

Regards
Subash
srees Nivas
Ranch Hand

Joined: Oct 05, 2009
Posts: 51
Hi,

As per my understanding, there are two questions.

1) You want to create one pool instance of the ConnectionPool class for each database.

2) Depending on what is requested, you may have to connect to a variable number of databases.

Answer for the first question is "Singleton", as there is a need to create only one pool instance.

Answer for the second question is "Factory Method", as dynamically need to connect to the requested database.

Best Regards,
Sri.


deepak adlakha
Ranch Hand

Joined: Jul 27, 2001
Posts: 325
I was thinking why not Abstract Factory as correct option. as its clearly written that there are different databases, so depending on parameter, that factory can create object. unless until we dont want to make singleton for each different databases.
srees Nivas
Ranch Hand

Joined: Oct 05, 2009
Posts: 51
deepak adlakha wrote:I was thinking why not Abstract Factory as correct option. as its clearly written that there are different databases, so depending on parameter, that factory can create object. unless until we dont want to make singleton for each different databases.


Why not abstract factory is, because there are different data bases but there is no need of family of objects for that database.

I mean we'll be handling with connection object and can be created by the factory method dynamically.

If there are multiple(family of) related objects for that database to be created then abstract factory would do.

You can correct me if I'm wrong.

Thanks,
Sri.
deepak adlakha
Ranch Hand

Joined: Jul 27, 2001
Posts: 325
yes we can live with factory also. But the back to original post..what should be correct answer factory or singleton ?
srees Nivas
Ranch Hand

Joined: Oct 05, 2009
Posts: 51
deepak adlakha wrote:yes we can live with factory also. But the back to original post..what should be correct answer factory or singleton ?


The question itself is having ambiguity. I mean as I said in my previous post, it is having two questions.

Just to answer your question, both Factory Method AND Singleton.

I do not have any other choice. Do you :-) ?

Best regards,
Sri.
deepak adlakha
Ranch Hand

Joined: Jul 27, 2001
Posts: 325
Yes i agree question itself is having ambiguity
prathap venkata naga yelugula
Ranch Hand

Joined: Aug 13, 2008
Posts: 243
Nice Post I have also Observed like this situation.

Cheers!
Prahap.
 
jQuery in Action, 2nd edition
 
subject: Pattern used in the qn