I am somewhat confused while understanding Flyweight pattern.I read dofactory article but it is somewhat complex.Then i read one forum discussion at http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/940e89fb-c69d-480e-bdde-a2bdb8c38a87 which is different in UML from what dofactory says.
Can you please give me any example from your experience when you used flyweight probably supported by code.
Flyweight as per dofactory: A fine-grained instance used for efficient sharing. So what I can make out from this is [considering fat server and dumy client]: Rather than providing the complete object (which will be heavy for the client to use) to the client(s), the server will provide only part of the object which would not be heavy for client to handle. This undoubtly helps in performance of client(s), helps in sharing of object(s).
A typical scenario could be: your server is holding a dataset sales leads and your client only needs a specific lead details from the complete set, so in this case rather cosuming complete dataset the client can make use of the specific lead datatable which is comparatively light and less resource frugal.
A relative example of such approach could be usage of JSON
let us know this helps you.
Manish Patil http://patilmanishrao.wordpress.com Posting is provided AS IS with no warranties, and confers no rights.
when you use
string s = "Hai";
string s2 = "Hai";
Though the instances are different, both s1 and s2 are pointing to same memory location. This can be checked by looking at the hashcode s.GetHashCode(). However when s2 is changed to something else, it changes its reference to point to new memory location.
you can even store the string in a pool using String.Intern method..
I thing this mechanism is one of the implementation of flyweight pattern