1/8
The code smells to look out for in COMP2511
What are the features of a “Refused Bequest” code smell?
When a class inherits behaviour it doesn’t need so it either doesn’t do anything or throws an error.
This can muddy a classes functionality or perceived behaviour.
SOLUTION: Decay useless behaviour into an interface and implement the interface into the relevant classes.
What are the features of a “Long Parameter List” code smell?
When a classes method/constructor has a very long parameter list.
Makes a class less legible, increases coupling
SOLUTION: Decay parameter list into a data class and pass the class instead.
What are the features of a “Large Method/Class” code smell?
When a class is particularly large (over 200 lines) or has a method that is particularly large (over 50-60 lines).
SOLUTION: Decay behaviour into subclasses/new methods.
What are the features of a “Similar Code Fragments” code smell?
When a classes have code snippets that are very similar or identical to each other.
SOLUTION: Decay the shared behaviour into the superclass or a shared interface.
What are the features of a “Feature Envy” code smell?
When a class cares more about the functionality/data of another class.
SOLUTION: Move the offending methods to the class that the method actually gives a gaf about.
What are the features of a “Divergent Change” code smell?
When making changes to a single class, you must make modifications in multiple places within the class.
SOLUTION: Separate the reasons for change into separate classes.
What are the features of a “Shotgun Surgery” code smell?
When making changes to a single class, you must make modifications in multiple places in other classes.
SOLUTION: Consolidate related changes into a single class/move offending methods to relevant classes.
What are the features of a “Lazy Class” code smell?
A class that is very small and doesn’t do a lot.
SOLUTION: Decay functionality into exisiting classes.
What are the features of a “Data Class” code smell?
A class that only holds data and doesn’t actually complete any functionality other than getting/setting.
SOLUTION: Check if there is functionality that is better held by the data class rather than another class, otherwise decay data class into a super class?