Feature Envy

Written by

in

Description

This Smell occurs when an abstraction becomes more focused on the methods and fields of other abstractions rather than its functions and variables. This issue typically arises when data and functionality that should be kept together are separated across multiple components. It is often, but not always, accompanied by another smell, Data Service.

Context

Derived from: “Feature Envy”
Sometimes behavior is purposefully kept separate from the element that holds the data. The usual advantage of this is the ability to dynamically change the behavior. Depending on the architecture, this smell can be applied differently.

Cause

This smell may occur after further data is moved to a data component. If this is the case, you may want to move the operations on data to this component as well.

Detection

Searching for a service that utilizes the capabilities of a data service. Specifically, there exists a serving relationship between the data service and feature envy.

Solution

As a basic rule, if things change at the same time, you should keep them in the same place. Usually data and functions that use this data are changed together (although exceptions are possible).

Cypher query

MATCH p=(f)<-[:ServingRelationship|AssociationRelationship]-(a)-[r:AccessRelationship]->(d) <br /> WITH p, a <br /> WHERE NOT EXISTS{<br />(a)-[r1:AssignmentRelationship|CompositionRelationship|AssociationRelationship|AggregationRelationship|RealizationRelationship]-(s) <br />WHERE NOT s:ApplicationService or s:BusinessService or s:TechnologyService <br />} <br /> RETURN p

Cypher count query

MATCH p=(f)<-[:ServingRelationship|AssociationRelationship]-(a)-[r:AccessRelationship]->(d) <br /> WITH p, a <br /> WHERE NOT EXISTS{<br />(a)-[r1:AssignmentRelationship|CompositionRelationship|AssociationRelationship|AggregationRelationship|RealizationRelationship]-(s) <br />WHERE NOT s:ApplicationService or s:BusinessService or s:TechnologyService <br />} <br /> MATCH (f)<-[:ServingRelationship|AssociationRelationship]-(a)-[r:AccessRelationship]->(d) return count (distinct f)

Diagram

Diagram for Feature Envy

Tags

soa, microservices, business, application, technology, The Couplers, between elements

Related smells

All smells