Data Envy

DataEnvy is a code smell similar to FeatureEnvySmell, but focused on the Data of the other object. The routine that has DataEnvy typically doesn't use much or any data from its container object.

Example:

        For Each car As Car In CarList?
            car.Acc = car.GetCurrentAcc?(car.Acc, time)
            car.Speed = car.GetCurrentSpeed?(car.Speed, car.Acc, time)
            car.CurPos? = car.GetCurrentposition?(car.CurPos?, car.Speed, time)            
        Next

In this case, the routine is using one reference to a local member, time, 8 references to data in another object, and 3 references to routines in that object.

This routine clearly wants to be in the Car object.

        For Each car As Car In CarList?
            car.CalcCurrentPosition?(time)
        Next


EditText of this page (last edited July 23, 2014) or FindPage with title or text search