aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes is this good implementation of flyweight pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "is this good implementation of flyweight pattern" Watch "is this good implementation of flyweight pattern" New topic
Author

is this good implementation of flyweight pattern

vijay jacob
Ranch Hand

Joined: Jul 02, 2013
Posts: 57

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

Joined: Jul 02, 2013
Posts: 57
Any suggestion anybody has
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2402
    
  28

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is this good implementation of flyweight pattern