Design smells PDF

Title Design smells
Course O-O Design & Programming
Institution University of New South Wales
Pages 3
File Size 227.9 KB
File Type PDF
Total Downloads 54
Total Views 130

Summary

Summary for design smells...


Description

Long method: - Reduce length via extract method - move code from methods into new methods, and run these new methods in the original

-

Introduce parameter object

-

Replace method with method object, or extract class

-

Replace temp with query - Query the method instead of using a variable. - Loops and conditional operators are a good clue that code can be moved to a separate method Large Class:

-

Bundle groups via extract class

Long parameter list: - Move all the parameters into body and use getters

Data Clumps: - When different parts of code contain the same variables, can lead to long parameter list - Use move method - Extract class - Introduce parameter object - e.g. changing start and end time to a daterange - Preserve whole object Refused bequest: - When a subclass only uses some methods and properties inherited from parents - Replace inheritance with delegation - If inheritance is required we can - create new subclass - apply push down field to move field relevant only to subclass from superclass I.e for a transport class, we can move field model from transport to car - extract sub-class class to combine above Duplicate code: - Extract method: basically make a new function/ method - Use the pull up field if 2 classes on the same level contain - If inside a constructor, use pull up constructor body - If similar code, use form template method - If do the same but use different algo, apply substitute algo - If in 2 different classes, use extract superclass Feature envy - When a method is more interested in a class other than the one it is - Move method to relevant class via move method Divergent change, Data classes

-

Classes with only setters and getters Move method: move method into the right class, move getter into customer class

Lazy classes - Classes arent doing much to justify existence - Move lazy class into the correct class Switch statements - Use strategy pattern instead...


Similar Free PDFs