• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about Mock Exam Question

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are two benefits of the Singleton pattern? (Choose two.)

A. It encourages use of global variables.
B. It controls access to a single instance.
C. It permits a variable number of instances.
D. It allows a collection of objects to be manipulated as a single object.

Given answer is B,C

According me answer should be A,B

Please Help
Thanks
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wiki to the rescue Singleton pattern

In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. Sometimes it is generalized to systems that operate more efficiently when only one or a few objects exist. It is also considered an anti-pattern since it is often used as a euphemism for global variable.


So "A. It encourages use of global variables." is not a benefit.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the answer of above question should be B only not B,C?
 
Dawid Augustynowicz
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C is also true - that's the purpose of singleton - it allows to create only one instance of object (or pool of objects)
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Now i got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic