Friday, January 29, 2021

Code Deodorant

Reference

https://refactoring.com/catalog/

https://www.jyt0532.com/toc/refactoring/

1. Long Function

Extract Function

Replace Temp with Query

Introduce Parameter Object

Preserve Whole Object

Replace Function with Command

Decompose Conditional

Replace Conditional with Polymorphism

Split Loop (重構與效能) 有時候為了讓程式碼更容易維護, 犧牲效能

2. Large Class
3. Long Parameter List

4. Data Clumps

5. Primitive Obsession

Replace Type Code with Subclasses

Replace Conditional with Polymorphism

Extract Class

Introduce Parameter Object

6. Repeated Switch

Replace Conditional with Polymorphism

Remove Flag Argument

7. Temporary Field

Extract Class

8. Alternative Classes with Different Interfaces

Move Function

Extract Superclass

9. Refused Bequest

Replace Superclass with Delegate (延伸)

10. Divergent Change

Move Function

Extract Function

Extract Class

11. Shotgun Surgery

Move Function

Combine Functions into Class

Combine Function into Transform 

Split Phase

Inline Function

12. Parallel Inheritance Hierarchies

Move Method

Move Field

13. Duplicate Code

Extract Function

14. Lazy Class

Inline Function

Inline Class

Collapse Hierarchy

15. Speculative Generality

Inline Function

Inline Class 

Change Function Declaration

16. Data Class

Remove Setting Method (this value can't change)

Move Function

Extract Function

Split Phase

17. Dead code

Remove Unreachable Code

18. Feature Envy

Move Function

Extract Function

19. Message Chains

Hide Delegate

Extract Function

Move Function

20. Middle Man

Inline Function

Replace Superclass with Delegate

Replace Subclass with Delegate

21. Inappropriate Intimacy

Move Field

Extract Class

Hide Delegate

Replace Inheritance with Delegation (https://learnku.com/docs/99-software-pattern/delegation-pattern/12018)

22. Comments

Extract Function

Change Function Declaration

23. Global Data

24. Mutable Data

Encapsulate Variable

Extract Function 

Remove Setting Method (this value can't change)

25. Mysterious Name

Change Function Declaration

26. Incomplete Library Class 

Move Method

27. Loops

28. Insider Trading

Move Function

Move Field

Replace Subclass with Delegate




No comments:

Post a Comment

n8n index

 【n8n免費本地端部署】Windows版|程式安裝x指令大補帖  【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能