Flyweight Getting interpretation

Scenario: a fixed part of large numbers of objects held by the public

For example, suppose we render to the forest each tree has a tree grid, trunk texture, leaf texture, position, light, bark color, leaf color ......

When large quantities of produce can not be said to have customized each tree texture, so the grid, such as those inherent in (grid and tree branches Texture, leaves) extract 

From

class Tree
{
  private:
    Mesh mesh_;
    Texture bark_;
    Texture leaves_;
    Vector position_;
    double height_;
    double thickness_;
    Color barkTint_;
    Color leafTint_;
};

Replacement for the

class TreeModel
{
  private:
    Mesh mesh_;
    Texture bark_;
    Texture leaves_;
};
class Tree
{
  private:
    TreeModel* model_;
    Vector position_;
    double height_;
    double thickness_;
    Color barkTint_;
    Color leafTint_;
};

So that each tree pointing to the example of fixed no longer hold himself a complete example

On how to extract an inherent part of the game program mode this region collectively, the "nothing to do with the context" This is important haha  

As entry Flyweight understand, if spectators classic error please point out errors

Guess you like

Origin www.cnblogs.com/chenggg/p/11323749.html