• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pattern used in the qn

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes i agree question itself is having ambiguity
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice Post I have also Observed like this situation.

Cheers!
Prahap.
reply
    Bookmark Topic Watch Topic
  • New Topic