Lazy Component

Written by

in

Description

A component that is not doing enough to pay for itself should be eliminated. Those components have limited responsibilities. That way, they clutter design, creating unnecessary abstractions. Although delegation is good, and one of the key fundamental features of abstractions, too much of a good thing can lead to objects that add no value, simply passing messages on to another component.

Context

Derived from: “Lazy Class” and “Middle Man”
This smell can be the result of overzealous elimination of Message Chains. Sometimes a Lazy Component is created in order to delineate intentions for future development or to avoid dependencies between elements (e.g. Decorator Pattern). In this case, try to maintain a balance between clarity and simplicity in your architecture.

Cause

This smell can be the result of overzealous elimination of Message Chains. In other cases, it can be the result of the useful work of a functional component being gradually moved to other components during refactoring, for example. The original component remains as an empty shell that has become ridiculously small and doesn’t do anything other than delegate.

Detection

Transient associations. Temporary, short-duration objects. Single-operation elements that exist only to “seed” or “invoke” other components through temporary associations. Often can be identified through the name containing “controller” or “manager”.

Solution

Collapse Hierarchy and redistribute functionality: After their removal, however, the functionality that was “provided” must be replaced. This is easy with a simple adjustment to correct the architecture.

Example

Consider the case of an e-commerce application that has two classes: namely, Best-SellerBook and Book. Whenever the client wants to create a best-seller book, it creates an instance of a BestSellerBook. Internally, BestSellerBook delegates all the method calls to the Book class and does nothing else. Clearly, the BestSeller-Book abstraction is unnecessary since its behavior is exactly the same as the Book abstraction.

Cypher query

MATCH p=(n) <br />  WHERE n.Label contains 'controller' or n.Label contains 'manager' <br /> RETURN p

Aliases

Poltergeist, Freeloader, Unnecessary Abstraction, Gypsy

Tags

soa, microservices, business, application, technology, The Dispensables, The Couplers, automatic detection

Related smells

All smells