Refactoring Why should I do refactoring? for what? => In my case, to solve problems about complex, dirty and heavy codes. To understand easily the
In Third chapter, It says there are bad smells in code. Yes, it means what are bad or worse ways and screw my code up.I would try to show those ways.M
Extract fragment of code into its own function named after its purpose.toYou know what's the code doing without reading the detailsShort function is e
Get rid of the function when the body of the code is just as clear as the nameto MotivationWhen Indirection is needless (simple delegation) becomes ir
Inline VariableRemove variable which doesn't really communicate more than the expression itself.to
Inline VariableRemove variable which doesn't really communicate more than the expression itself.to
Rename a function, change list of parameterstoMotivationEasier to understandEasier to reuse, sometime better encapsulation
Encapsulate a reference to some data structuretoMotivationProvide a clear point to monitor changes and use of the data, like validation.
Make shared variable's name can self-explainto
Replace groups of data items that regularly travel together with a single data structuretoMotivationMake explicit the relationship between the data it
Form a class base on group of functions that operate closely on a common datato
Takes the source data as input and calculates all the derivations, putting each derived value as a field in the output datatoMotivationAvoid duplicati
Split code which do different things into separate modulestoMotivationMake the different explicit, revealing the different in the codeBe able to deal
Create record (class) from object(객체로부터 레코드(클래스)를 만든다)totoMotivation1\. Hide what's stored and provide methods to get value객체를 사용하면 어떻게 저장했는지를 숨긴 채 세가
A method returns a collection. Make it return a read-only view and provide add/remove methods(컬렉션 변수로의 접근을 캡슐화 하면서 게터가 컬렉션 자체를 반환하도록 한다면, 그 컬렉션을 감싼 클래
Create class for data(데이터를 위한 클래스 만들기)toMotivation1\. Encapsulate behaviour with data데이터 캡슐화Procedure1\. Encapsulate a variable if it is not already e
Extract the assignment of the variable into a function(함수 안의 할당된 변수를 추출하기)toMotivationAvoid duplicating the calculation logic in similar functions비슷한
(클래스 추출하기)Extract class base on a subset of data and a subset of methods(데이터의 부분집합과 메소드들의 부분집합들을 클래스로 추출하기)toMotivationSmaller class is easier to unde
Merge class if class isn't doing very much. Move its feature to another class then delete it.(클래스가 뚜렷한 역할이 없을 경우 클래스를 합치기.)toMotivationClass is no lon
(위임 제거하기)A client is calling a delegate class of an object, create methods on the server to hide the delegate.(클라이언트가 겍체의 위임 클래스를 호출한다. 서버에 위임을 숨길 메서드
(중간자 삭제)Client call the delegate directly(클라이언트가 위임을 바로 호출하게 한다.)toMotivationWhen there are too many delegating methods너무 많은 위임메소드가 있을때 용이하다Procedure
(알고리즘 대체하기)Replace complicated algorithm with simpler algorithm(복잡한 알고리즘을 간단한 알고리즘으로 대체하기)toMotivationChange to algorithm which make changes easierThe