This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pattern used in the qn

 
Subash Murugan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i agree question itself is having ambiguity
 
prathap venkata naga yelugula
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice Post I have also Observed like this situation.

Cheers!
Prahap.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic