2

I'm using a complicated object design where I use the Flyweight pattern to limit certain non-static variables between multiple instances of a class. If both objects (the flyweight info and the class containing it) are Serializable, and a list of those cards is transferred from a wcf service to a client, does the client maintain the pattern (ie only one copy of the flyweight info for multiple instances of the higher class)? I'm going to give a slight code example below, in case I'm not explaining myself well.

public class Flyweight
{
    public Image image;
}

public class SmallObject
{
    public Flyweight fly;
}

Where a list contains 50+ SmallObjects, but uses the Flyweight pattern to only create enough Images for each separate type of object. It can't be a static variable because there are different types of SmallObjects that can't be represented by subclasses due to design restrictions. What I need to know is if the client receives 50+ discrete Flyweight objects, or the pattern is maintained and he only receives 1 Flyweight for each type.

Mike Beck
  • 35
  • 4

1 Answers1

1

The pattern is not maintained. You'll need to use [OnDeserialized] to manually re-build the referencing you want.

phillipwei
  • 1,243
  • 2
  • 12
  • 25