Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between Flyweight and Singleton Pattern

 
Gunaselan Varathan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am having hard time in understnding the difference between Flyweight and Singleton patterns based on Behaviour and uses.

can some one help me on this.

in singleton pattern is used to
controls the number of instances of a class that can be created to a predefined constant, typically but not always

in Flyweight pattern is used to
Use sharing to support large numbers of fine-grained objects efficiently.

i see both are used to control instance and share instance. is there a scenario when to use each of this
 
jay roy
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my understanding. correct me if i am wrong guys :roll:


singleton pattern is a CREATIONAL pattern in which only one instance is created and the same instance is reused multiple times by different users.

Flyweight pattern is a STRUCTURAL pattern which is useful in scenarios where there are lot of objects which share some common intrinsic information.Instead of storing the common intrinsic information n times for n pbjects, it is stored only once in one object and is referenced by all the objects which want to use it.
(This object which contains all the common intrinsic information is called
the flyweight object)


any comments appreciated..
 
Gunaselan Varathan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic