Flyweight design pattern RRS feed

All replies

  • Can somebody please respond to this post.



    Friday, February 10, 2012 9:39 AM
  • Hi,

    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.

    Manish Patil's Blog

    ↑ Grab this Headline Animator

    Wednesday, March 7, 2012 11:26 AM
  • An example of the Flyweight pattern is how fonts are handled in a graphic engine. The basic idea is that you have a single immutable instance of a character that is retrieved from a shared repository or collection.

    Wednesday, March 14, 2012 11:32 PM
  • 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


    Thursday, March 15, 2012 9:37 AM