Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is this good implementation of flyweight pattern

 
vijay jacob
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is account migration from one mobile provider to another. Bascially we have list of accounts to be migrated to which corresponidng provider.

So basically the service provider object will be mainly one of the three provider .So this data is static can be shared.





So basically here we save the creation of serviceProvider obj.


Please let me know your view on the same .
Also please share your real time business scenarion where you have applied.
 
vijay jacob
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestion anybody has
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is you ServiceProvider an heavyweight object? Does it have state? If no, then it's not flyweight. Also, it's not really a flyweight object unless you are sharing Service provider among multiple instances of MigAccount.

Also, an important thing to note is that not all cases of multiple objects sharing the same object is an example of the flyweight pattern. Ther3e are a lot of patterns that are based on multiple objects dependent on a single object. What matters is not that they are sharing the object, but why they are sharing the object. What you have described here looks more or less like a service injected into a client. Nothing here tells me that it's a flyweight pattern

It's a flyweight pattern only when the shared object (or pool of objects) stores the state and they are immutable. When the state changes, instead of creating an object every time the state of the object changes, you get a object from the pool that represent the new state.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic