As per IBMSP, Global Butterfly is a structural pattern for an object that has many global dependents. Changes to a global butterfly have a significant impact on the rest of the system. Global dependents include both direct (immediate) as well as indirect dependents. Applies to: Classes, Inner classes, Interfaces, Packages. All relationships are considered – Objects and interfaces accessed, referenced, called, contained, instantiated, implemented, thrown (exceptions).
- Since too many components are dependent on a Global Butterfly, a small change in this object has a
- Replacing a global butterfly component independently is almost impossible.
- System becomes fragile and non-modular. Refactoring becomes a very complex task.
- Testability and maintainability are affected.
- A Global Butterfly object is used by too many other objects. Usage can be in form of objects and interfaces accessed, referenced, called by, contained in, instantiated by, implements, extends, objects thrown (exceptions) than a human can keep in short term memory.
- TextArea is represented as a Pink block at the center.
- TextArea has 30 dependents
- The rectangle in blue represents objects that are immediate dependents of TextArea ( a direct reference to of TextArea object)
- The clusters of objects in yellow represent objects dependent on direct dependents of TextArea (inner rectangle objects).
- A continuous arrow emerging from TextArea indicates that an object at the arrow end directly depends (contains) TextArea object.
- A dashed arrow emerging from TextArea indicates that an object at the arrow end is using TextArea object an object from one of the outer clusters calling this dependent object (indirect dependency on TextArea)
- The directly depending are C3, C1, C6, C2 etc and the indirect dependencies are C11, C14, C26, C18, C20 etc.
- Only basic system interfaces or utility classes should be allowed to become Global Butterflies. Interfaces exist for the purpose of being extended by other classes and are acceptable Global Butterfly candidates that cause no harm to the system.
- Promote a design that deploys a low degree of Coupling (low value for the KPI – Coupling Between Objects) for each class.
- Group classes with
related/similarfunctionality into a common hierarchy (change Has-A relationship to Is-A relationship).