• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design Pattern Sample Q

 
Chetan Mehta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the two benefits of SIngleton pattern
A. It encourages use of global variable.
B. It control access to single instances.
C. It permits variable number of instances
D. It allows collection of objects to be manipulated as single object
I think correct ans is B &D
please tell me ur views...
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answers are B and C. you can have variable number of instances.
 
Chetan Mehta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You may be correct
Look at following sample, this makes us think that option - d can also be correct answer
Public class MazeFactory
{
private static MazeFactory instance = null;
public static MazeFactory instance (String name)
{
if (instance == null)
{
if (name.equals ("enchanted")
instance = new EnchantedMazeFactory ();
else if (name.equals ("agent")
instance = new AgentMazeFactory ();
}
return instance;

}
}
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
D. is the intent of Composite pattern .. As far as the example you have quoted it shows a combination of Factory Pattern and Singleton pattern.
Hope it helps..
Anil
 
Chetan Mehta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, that helps thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic