Shotgun Surgery

Written by

in

Description

Generally, when many abstractions are dependent to a single abstraction, any changes in the single abstraction may force some modifications in the dependent abstractions. This smell is evident when you must change lots of pieces in different places of the system simply to add a new or extended piece of behavior.

Context

Derived from: “Shotgun Surgery”

Cause

A single responsibility has been split up among a large number of classes. This can happen after overzealous reduction of Multifaceted Abstraction. All was well as long as the structure stayed small. But with new components being added, making changes has become harder and harder.

Detection

In the ArchiMate modeling language, the relation types describing dependency are serving, association, access, and influence. For detection, we first check whether there exists a one-to-many relationship with the specified relation types. The size of “many” may differ depending on the organization or enterprise.

Solution

Move existing behaviors into a single component. If there’s no component appropriate for this, create a new one. If moving code to the same element leaves the original one almost empty, try to get rid of these now-redundant components.

Example

Every time you make a subclass of one class, you have to make a subclass of another.

Cypher query

MATCH (a)-[r:ServingRelationship|AssociationRelationship|InfluenceRelationship|AccessingRelationship]->() <br /> WITH a, COUNT(r) AS relCount <br /> MATCH p=(a)-[r]-(b) <br /> WHERE relCount> $abstractionsCnt <br /> RETURN p <br />

Cypher count query

MATCH (a)-[r:ServingRelationship|AssociationRelationship|InfluenceRelationship|AccessingRelationship]->() <br /> WITH a, COUNT(r) AS relCount <br /> MATCH p=(a)-[r]-(b) <br /> WHERE relCount> $abstractionsCnt <br /> RETURN count (distinct a)

Diagram

Diagram for Shotgun Surgery

Tags

soa, microservices, business, application, technology, The Change Preventers, between elements

Query parameters

[
    {
        "name": "abstractionsCnt",
        "type": "number",
        "default": 3,
        "description": "The permitted number of abstractions that may depend on a single abstraction."
    }
]

Related smells

All smells