This anti-pattern is on the lines of Global Butterfly but differs in its scope of dependents. As per IBMSP, Local Butterfly is a structural pattern for a component that has many immediate dependents. The scope of dependents is limited to immediate dependents that directly access, use, reference, or contain the Local Butterfly.

Impact

  • The impact is similar to that of Global Butterfly but limited in scope.
  • A small change in the Local Butterfly impacts all immediate dependent objects.
  • Testability and maintainability are affected.

Characteristics

  • Too many objects directly depend on a Local Butterfly. Similar to a Global Butterfly, its dependence can be in form of access, reference, call, contained, instantiation, implements, extends, objects thrown (exceptions). Only direct/immediate dependents are considered.

Example(s)

  • Using the tool Structural Analysis for Java to analyze TextArea application revealed that about 18 percent of objects in TextArea application are Local Butterflies.
  • TextArea is represented as a Pink block at the center.
  • TextArea has 19 immediate dependents.
  • The rectangle represents objects that are immediate dependents of TextArea.
  • Continuous arrows emerging from TextArea indicate that objects at the other end either contain, references, calls, or extends SimpleNode object.
  • Dashed arrows emerging from TextArea indicate that object at the other end use TextArea object.
  • Any changes in the TextArea can break these classes.

Guidelines

  • Only basic Interfaces or utility classes should be allowed to become Local Butterflies.
  • Avoid a design that deploys a low degree of Coupling (low value for the KPI – Coupling Between Objects) for each class.
  • Group classes with related / similar functionality into common hierarchy (change Has-A relationship to Is-A relationship).