Friday, 22 November 2013

Flyweight Design pattern - Class Diagram

Master Software Architecture!

Subscribe to Ram N Java for clean code, UML diagram explanations, and beginner-friendly programming lessons!

SUBSCRIBE NOW

What is the Flyweight Class Diagram?

The Flyweight Design Pattern is a structural pattern designed to handle high volumes of fine-grained objects efficiently by sharing common state. The Class Diagram provides a blueprint of the architectural relationships between the participants that make this memory-sharing possible.

By defining clear responsibilities across separate interfaces and classes, the pattern ensures that shared data remains untouched while context-dependent parameters can be passed in dynamically.

Key Participants in the Class Diagram

  • Flyweight Interface: Declares the contract and operation methods through which flyweights can receive and act upon extrinsic state passed from the outside.
  • ConcreteFlyweight: Implements the Flyweight interface and stores the internal intrinsic state that is immutable and shared across multiple contexts.
  • UnsharedConcreteFlyweight: Represents instances where sharing is not required or feasible; not all subclasses of the Flyweight interface need to be shared.
  • FlyweightFactory: Manages a pool or cache of existing flyweight objects. When requested, it returns an existing instance from the cache or creates a new one if it does not yet exist.
  • Client: Maintains references to flyweight objects, computes or stores the extrinsic state, and passes it to the flyweight when invoking operations.

Structural Benefits & Best Practices

  • Strict Object Separation: Clear division between intrinsic (stored inside) and extrinsic (supplied by caller) state keeps memory usage predictable.
  • Centralized Factory Control: The factory enforces object pooling so that duplicate objects with identical intrinsic states are never created.
  • Clean UML Architecture: Easy to interpret and implement across enterprise applications, graphics rendering engines, and document editors.

Watch More Related Design Pattern Tutorials


Click here to watch in Youtube : https://www.youtube.com/watch?v=WjBsuNfIoOY

Click the below Image to Enlarge
Flyweight Design pattern - Class Diagram

















See also:

  • Flyweight Design pattern - Introduction
  • Flyweight Design pattern - Real Time Example
  • Flyweight Design pattern - Sequence Diagram
  • Flyweight Design pattern - Implementation
  • Flyweight Design pattern - Key Points
  • All Design Patterns Links
  • 1 comment:


    1. Class diagrams are used around the world to get a quick overview of a system.It describes the structure of a system by showing its classes, attributes and operations of those classes and the relationship between those classes. You can have a deep understanding with the resources in Creately diagram community. Please refer this UML class diagram templates to learn more.

      ReplyDelete

    Tutorials