• Design patterns,  Java Design Patterns,  Structural Design Pattern

    Flyweight Design Pattern

    Some programs require to have a large number of objects that have some shared state among them. Consider for example a game of war, were there is a large number of soldier objects; a soldier object maintain the graphical representation of a soldier, soldier behavior such as motion, and firing weapons, in addition soldier’s health and location on the war terrain. Creating a large number of soldier objects is a necessity however it would incur a huge memory cost. Note that although the representation and behavior of a soldier is the same their health and location can vary greatly. Why Fly Weight? The intent of this pattern is to use…

    Comments Off on Flyweight Design Pattern