6. , . Tool Refactoring public int getCharge(int quantity) {
public int getCharge(int quantity) { int charge = 0; int charge =
0; Date now = new Date(); Date now = new Date(); // Summer if
(isSummerTime(now)) { if (now.before(SUMMER_START)||
now.after(SUMMER_END)) { charge = quantity * WINTER_RATE + charge =
quantity * WINTER_RATE + WINTER_SERVICEC_CHARGE;
WINTER_SERVICEC_CHARGE; } else { } else { charge = quantity *
SUMMER_RATE; charge = quantity * SUMMER_RATE; } } return charge;
return charge } } private boolean isSummerTime(Date now) { return
now.before(SUMMER_START) || now.after(SUMMER_END); }
7. : ? ? ?
8. : ? , , . ,
9. : (10~30), .
10. : Publish Ex) Android Service.onStart() I/F Delegation :
API Publish Throw Delegation : Super Exception , ?
11. : , . With design I can think very fast, but my thinking is
full of little holes Alistair Cockburn Role , . . . Complexity
12. : . . , .
13. () Switch
14. : Obvious Copy & Paste Unobvious (ex, , ) ExtractMethod
ExtractMethod -> Pull Up Field or Pull Up Method -> Form
Template Method
15. : . People often make assumptions based on the object names
alone Word Cunningham Rename Method Rename Field Rename Constants
Tip ! add, register, put, create -> add
17. : Class A Class B (private .. .. ) amethod() xmethod()
bmethod() ymethod() Move Method Change Bidirectional Reference to
Unidirectional Extract Hierarchy-> Hide Delegate
67. : public class Employee { private int type; private static
final int ENGINEER = 0; 1 private static final int SALESMAN = 1;
private static final int MANAGER = 2; public Employee(int type) {
this.type = type; Type } Replace Type Code with public int
calculatePayment() { switch (type) { case ENGINEER: return
monthlySalary; State/Strategy case SALESMAN: return monthlySalary +
commission; case MANAGER: return monthlySalary + bonus; Replace
Type Code with default: throw new RuntimeException("Incorrect
Employee"); Subclass }} public String getJobTitle() { 2 switch
(type) { case ENGINEER: Replace Conditional with return "Engineer";
case SALESMAN: Class return "Salesman"; case MANAGER: return
"Manager"; default: throw new RuntimeException("Incorrect
Employee"); } }} 67 Confidential 12/13/2011
68. Boolean 68 Confidential 12/13/2011
69. 69 Confidential 12/13/2011
70. 70 Confidential 12/13/2011
71. : Book Book height title genre category width author weight
price getDiscount() getRequiredDeliveryRoom() content Book , , 71
Confidential 12/13/2011
72. : ->Replace Data Value with Object -> : Replace Type
Code with Class : Replace Array with Object 72 Confidential
12/13/2011
73. Refactoring : Replace Data with Object User +firstName:
String +lastName: String Order Customer Replace Data
with+orderNumber: String Object Order +firstName:
String+customeFirstNamer: String 1 1 +lastName:
String+customerLastName: String +orderNumber+price:
float+addressState: String Address+addressCity: String
+state+addressStreet: String +city+addressZipCode1: String
+zipCode1+addressZipCode 2: String 1 1 +zipCode2+telAreaCode:
String+telNumber: String +getDeliveryCost() home Contact office
+areaCode +number 73 Confidential 12/13/2011
74. Refactoring : Replace Array with Object String[] row = new
String[3]; Performance row = new Performance(); row [0] =
"Liverpool"; row.setName("Liverpool"); row [1] = "15";
row.setWins("15"); 74 Confidential 12/13/2011
75. : public field getter/setter 1- : Encapsulate Field 2- :
Remove Setting Method 3-Collection : Encapsulate Collection 4- :
Extract Method and Move Method 5- , , public , getter/setter 75
Confidential 12/13/2011
79. : .( ) .( ) . , Is-A , Replace Inheritance with Delegation
Extract Subclass, Push Down Field, Push Down Method , . -> Java
Collection79 Confidential 12/13/2011
80. : Drawable Drawable +draw() Line +draw() Exception
+getArea() +getArea() , 0 Rectangle Circle Rectangle Circle Line
+getArea() Drawable +draw() Shape Line +getArea() +getLength()
Rectangle Circle80 Confidential 12/13/2011
81. Liskov Substitution Principle(LSP)Functions that use
pointers or references to base classes must be able to use objects
of derived classes without knowing it. , Square Rectangle . -> ,
LSP . Shape Rectangle.setWidth() Square.setWidth() . +getArea()
Shape Rectangle Circle +getArea()
+width+height+setWidth()+setHeight()+getWidth() Square Rectangle
Circle+getHeight() +width +width +height +height +setLength()
+setWidth() +setHeight() Square +getWidth() +getHeight()OOD IS-A
.81 Confidential 12/13/2011
82. Refactoring : Replace Inheritance with Delegation 82
Confidential 12/13/2011
83. : ( ) (private ) . . -> Self Encapsulate Field ->
Form Template Method -> Replace Inheritance with Delegation 83
Confidential 12/13/2011
88. : & Class A Class B Class A Class B .. .. .. attributeA
amethod() getX() amethod() bmethod() getY() bmethod() amethod()
private . - Move Method Move Method - Extract Hierarchy-> Hide
Delegate - Change Bidirectional Reference to Unidirectional88
Confidential 12/13/2011
89. Refactoring : Hide Delegate , (Delegate) . Client
Department . Law of Demeter . : . 89 Confidential 12/13/2011
90. Refactoring : Change Bidirectional Association to
Unidirectional . Bidirectional Association . -> Zombie Cluster
-> Coupling 90 Confidential 12/13/2011