45
Code Refactoring Presented by Steven Dec. 2016

Code Refactoring

Embed Size (px)

Citation preview

Page 1: Code Refactoring

Code RefactoringPresented by Steven

Dec. 2016

Page 2: Code Refactoring

Why

2

Page 3: Code Refactoring

3

Page 4: Code Refactoring

4

Page 5: Code Refactoring

FastRunnable

5

Page 6: Code Refactoring

FastRunnable

6

Page 7: Code Refactoring

Spaghetti Code

● program flow is conceptually like a bowl of spaghetti, i.e. twisted and tangled.

● complex and confusing control structures that are barely understandable

7

Page 8: Code Refactoring

8

Page 9: Code Refactoring

What

9

Page 10: Code Refactoring

● Code refactoring is the process of restructuring existing computer code without changing its external behaviour.

Code Refactoring

10

Page 11: Code Refactoring

在不改變軟體的外在行為下,改善既有軟體的內部設計。

11

Page 12: Code Refactoring

2 Advantages

6 Techniques

12

Page 13: Code Refactoring

Advantages

13

Page 14: Code Refactoring

Expressiveness

14

Page 15: Code Refactoring

Expressiveness

Complexity

15

Page 16: Code Refactoring

Expressiveness

Complexity

Readability

16

Page 17: Code Refactoring

17

Page 18: Code Refactoring

Expressiveness

Complexity

Readability

18

Page 19: Code Refactoring

Maintainability

Expressiveness

Complexity

Readability

19

Page 20: Code Refactoring

Maintainability

Expressiveness

Complexity

Readability

Extensibility

20

Page 21: Code Refactoring

Maintainability Extensibility

21

Page 22: Code Refactoring

Techniques

22

Page 23: Code Refactoring

Generalization ExtractionEncapsulation

Pulling-up Pushing-downRenaming

23

Page 24: Code Refactoring

Generalization ExtractionEncapsulation

Pulling-up Pushing-downRenamingcommon: private / (default) / protected / public

24

Page 25: Code Refactoring

Generalization ExtractionEncapsulation

Pulling-up Pushing-downRenamingcreate more general types, e.g., super-classes

25

Page 26: Code Refactoring

Generalization ExtractionEncapsulation

Pulling-up Pushing-downRenamingextract {classes, methods, funcions}fewer methods → clearer purpose and functionality

26

Page 27: Code Refactoring

Generalization ExtractionEncapsulation

Pulling-up Pushing-downRenaming

rename {methods, fields}

27

Page 28: Code Refactoring

Generalization ExtractionEncapsulation

Pulling-up Pushing-downRenaming

moving methods between parent/child classes

28

Page 29: Code Refactoring

Generalization ExtractionEncapsulation

Pulling-up Pushing-downRenaming

http://refactoring.com/catalog/index.html29

Page 30: Code Refactoring

How

30

Page 31: Code Refactoring

Encapsulation 31

Page 32: Code Refactoring

Encapsulation 32

Page 33: Code Refactoring

data / field → private

Setter & Getter

Encapsulation 33

Page 34: Code Refactoring

Generalization 34

Page 35: Code Refactoring

Generalization 35

Page 36: Code Refactoring

Generalization 36

Page 37: Code Refactoring

Generalization 37

Page 38: Code Refactoring

Generalization 38

Page 39: Code Refactoring

Renaming 39

Page 40: Code Refactoring

Renaming 40

Page 41: Code Refactoring

Conclusion

41

Page 42: Code Refactoring

● what

42

Page 43: Code Refactoring

● whatMaintainability

Extensibility43

Page 44: Code Refactoring

44

Page 45: Code Refactoring

45