SlideShare a Scribd company logo
1 of 15
Download to read offline
클린코드 스터디
16장. SerialDate 리팩토링
이데아게임즈 손진화
이 장의 내용
• org.jfree.date.SerialDate 클래스를
리팩토링 해보기
• 오리지널 코드
https://github.com/jfree/jcommon/tree/master/src/main/java/org/jfree/date
테스트 코드를 수행하자
• 존재하는 테스트 코드를 돌려서 모든 테스트
케이스를 성공적으로 통과하는지 확인
• 테스트 코드가 모든 기능들을 테스트 하는 지
확인
• Code Coverage Tool
Java : Clover https://ko.atlassian.com/software/clover
Cpp : gcov http://korea.gnu.org/manual/release/gcov/gcov_1.ko.html
코드 커버리지를 확인했더니…
• 코드 커버리지가 50% 밖에 되지 않았다!
• 모든 코드를 다 테스트 할 수 있도록 추가로
테스트 코드 작성 p484
• 새로 추가한 테스트 코드가 모두 성공할 수 있
도록 버그를 수정한다
본격적으로 리팩토링 시작
• 변경 이력 제거 [C1] p448 L1
변경 이력은 소스관리 툴에서 확인 가능하다
• 코드에 사용되는 언어 통일 [G1] p449 L67
java와 javadoc 으로 통일
• 클래스명 변경 [N1] [N2]
좀 더 서술적이고 추상 클래스에 맞는 이름으
로 변경
본격적으로 리팩토링 시작
• 구현 클래스에서만 사용하는 멤버변수를 구
현 클래스 안으로 이동 [G6] p450 L98
• 추상 클래스 안에 있는 구현 클래스 코드 제거
[G7] p466 L808
구현 클래스 생성 코드는 ABSTRACT
FACTORY 로 분리
DACORATOR, SINGLETON 적용
• 많은 수의 연관된 서브 클래스를 특정 그룹으
로 묶어 한번에 교체할 수 있도록 만든 디자인
패턴
http://jdm.kr/blog/192
• 주어진 상황 및 용도에 따라 어떤 객체에 책임
을 덧붙이는 패턴으로, 기능 확장이 필요할 때
서브클래싱 대신 쓸 수 있는 유연한 대안이 될
수 있다 [링크]
본격적으로 리팩토링 시작
패턴들이 적용된 결과 p352~p353
• 요일 상수를 enum으로 변경 [J3] p450 L109
• 필요 없는 주석 삭제 [C3] p451 L139
코드만 봐도 충분히 의미가 파악된다
• 사용하지 않는 코드 제거 [G9] p451 L144
본격적으로 리팩토링 시작
• 멤버 변수를 private로 변경 p451 L144
• 변수는 사용하는 곳과 가까운 곳에 선언
[G10] p505 L434
• 용어를 사용하여 의미를 명확하게 한다 [N3]
p452 L177
같은 의미를 가지는 수학적 용어로 이름 변경
본격적으로 리팩토링 시작
• 빈 기본 생성자 제거 [G12] p452 L213
어차피 컴파일러가 자동으로 생성해준다
• 리팩토링을 하면서 코드와 의미가 달라진 주
석 삭제 [C2]
• 다른 조건으로 같은 행동을 하는 코드 묶음
[G5] p454 L259~L263
중복된 코드를 제거하라
본격적으로 리팩토링 시작
• 같은 개념을 가진 코드는 같은 곳에 위치하도
록 이동 [G13] p453 250
요일을 enum으로 만들면서 수정할 필요가 생
김 p356
• 클래스 외부에 선언된 enum에 대한 연산을
하고 있다. 이 기능을 enum내부로 이동 [G14]
p456 L377 ~ p457 L426
달을 enum으로 만들면서 수정할 필요가 생김
p358
본격적으로 리팩토링 시작
• 모호한 표현을 제거하고 서술적인 표현으로
가독성을 높인다 [G16] p459 L495
p359
• 부적절한 static 표현 삭제 [G18] p461 L562
재정의 하지 않을 것이라는 보장이 없다 p360
• 임시 변수의 이름을 서술적으로 바꾼다 [G19]
p461 L593 -> p360
본격적으로 리팩토링 시작
• 모호하게 해석되지 않도록 명확한 이름으로
변경 [N4] p361
• 숨겨진 논리적 의도성을 드러내라 [G22]
p500 L247
추상 클래스와 연관 되어 있을 것 같은 동작이
구현클래스에 의존성을 가지고 있었다. 이를
메소드로 분리해 확실하게 드러낸다. p364
결과 코드
• 리팩토링을 하면서 계속 테스트 코드를 실행
하여 코드 품질을 유지하도록 한다
• https://github.com/ludwiggj/CleanCode/
tree/master/src/clean/code/chapter16/sol
ution

More Related Content

What's hot

Onion Architecture and the Blog
Onion Architecture and the BlogOnion Architecture and the Blog
Onion Architecture and the Blogbarryosull
 
Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]Pramati Technologies
 
Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)WSO2
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitecturePaul Mooney
 
Introduction to Event Driven Architecture
Introduction to Event Driven ArchitectureIntroduction to Event Driven Architecture
Introduction to Event Driven ArchitectureCitiusTech
 
IBM Maximo Performance Tuning
IBM Maximo Performance TuningIBM Maximo Performance Tuning
IBM Maximo Performance TuningFMMUG
 
Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...
Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...
Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...OutSystems
 
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...Jitendra Bafna
 
Deep dive into swift UI
Deep dive into swift UIDeep dive into swift UI
Deep dive into swift UIOsamaGamal26
 
Oracle SOA 12.2.1 Installation
Oracle SOA 12.2.1 InstallationOracle SOA 12.2.1 Installation
Oracle SOA 12.2.1 InstallationVijay Reddy
 
UNYOUG - APEX 19.2 New Features
UNYOUG - APEX 19.2 New FeaturesUNYOUG - APEX 19.2 New Features
UNYOUG - APEX 19.2 New Featuresmsewtz
 
HFM API Deep Dive – Making a Better Financial Management Client
HFM API Deep Dive – Making a Better Financial Management ClientHFM API Deep Dive – Making a Better Financial Management Client
HFM API Deep Dive – Making a Better Financial Management ClientCharles Beyer
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Patternjeetendra mandal
 
Azure Logic Apps
Azure Logic AppsAzure Logic Apps
Azure Logic AppsBizTalk360
 
Office 365 SaaS Mail Integration with SAP on Azure
Office 365 SaaS Mail Integration with SAP on AzureOffice 365 SaaS Mail Integration with SAP on Azure
Office 365 SaaS Mail Integration with SAP on AzureGary Jackson MBCS
 
Building .NET-based Serverless Architectures and Running .NET Core Microservi...
Building .NET-based Serverless Architectures and Running .NET Core Microservi...Building .NET-based Serverless Architectures and Running .NET Core Microservi...
Building .NET-based Serverless Architectures and Running .NET Core Microservi...Amazon Web Services
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 

What's hot (20)

Onion Architecture and the Blog
Onion Architecture and the BlogOnion Architecture and the Blog
Onion Architecture and the Blog
 
Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]
 
Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 
Introduction to Event Driven Architecture
Introduction to Event Driven ArchitectureIntroduction to Event Driven Architecture
Introduction to Event Driven Architecture
 
IBM Maximo Performance Tuning
IBM Maximo Performance TuningIBM Maximo Performance Tuning
IBM Maximo Performance Tuning
 
Git flow en github
Git flow en githubGit flow en github
Git flow en github
 
Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...
Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...
Automating Your Way to Greatness by Combining OutSystems CI/CD With the Power...
 
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...
 
Deep dive into swift UI
Deep dive into swift UIDeep dive into swift UI
Deep dive into swift UI
 
Oracle SOA 12.2.1 Installation
Oracle SOA 12.2.1 InstallationOracle SOA 12.2.1 Installation
Oracle SOA 12.2.1 Installation
 
UNYOUG - APEX 19.2 New Features
UNYOUG - APEX 19.2 New FeaturesUNYOUG - APEX 19.2 New Features
UNYOUG - APEX 19.2 New Features
 
HFM API Deep Dive – Making a Better Financial Management Client
HFM API Deep Dive – Making a Better Financial Management ClientHFM API Deep Dive – Making a Better Financial Management Client
HFM API Deep Dive – Making a Better Financial Management Client
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Azure Logic Apps
Azure Logic AppsAzure Logic Apps
Azure Logic Apps
 
Office 365 SaaS Mail Integration with SAP on Azure
Office 365 SaaS Mail Integration with SAP on AzureOffice 365 SaaS Mail Integration with SAP on Azure
Office 365 SaaS Mail Integration with SAP on Azure
 
Event storming
Event storming Event storming
Event storming
 
Building .NET-based Serverless Architectures and Running .NET Core Microservi...
Building .NET-based Serverless Architectures and Running .NET Core Microservi...Building .NET-based Serverless Architectures and Running .NET Core Microservi...
Building .NET-based Serverless Architectures and Running .NET Core Microservi...
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 

Similar to 클린코드 16장

Go로 새 프로젝트 시작하기
Go로 새 프로젝트 시작하기Go로 새 프로젝트 시작하기
Go로 새 프로젝트 시작하기Joonsung Lee
 
청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기Chris Ohk
 
테스트 기발 개발, TBD(Test based developement)
테스트 기발 개발, TBD(Test based developement)테스트 기발 개발, TBD(Test based developement)
테스트 기발 개발, TBD(Test based developement)도형 임
 
전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019
전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019
전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019devCAT Studio, NEXON
 
IoT 개발자를 위한 Embedded C에서 TDD를 해보자
IoT 개발자를 위한 Embedded C에서 TDD를 해보자IoT 개발자를 위한 Embedded C에서 TDD를 해보자
IoT 개발자를 위한 Embedded C에서 TDD를 해보자Taeyeop Kim
 
Chapter7~9 ppt
Chapter7~9 pptChapter7~9 ppt
Chapter7~9 pptInjae Lee
 
프로젝트 관리 및 지켜야 할 사항들
프로젝트 관리 및 지켜야 할 사항들프로젝트 관리 및 지켜야 할 사항들
프로젝트 관리 및 지켜야 할 사항들Lee Geonhee
 
Windows reversing study_basic_7
Windows reversing study_basic_7Windows reversing study_basic_7
Windows reversing study_basic_7Jinkyoung Kim
 
버전관리시스템 종류와 소개
버전관리시스템 종류와 소개버전관리시스템 종류와 소개
버전관리시스템 종류와 소개Jong-il Seok
 
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱PgDay.Seoul
 
[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기
[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기
[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기Ahreum Kim
 

Similar to 클린코드 16장 (12)

Go로 새 프로젝트 시작하기
Go로 새 프로젝트 시작하기Go로 새 프로젝트 시작하기
Go로 새 프로젝트 시작하기
 
청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기
 
테스트 기발 개발, TBD(Test based developement)
테스트 기발 개발, TBD(Test based developement)테스트 기발 개발, TBD(Test based developement)
테스트 기발 개발, TBD(Test based developement)
 
전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019
전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019
전형규, SilvervineUE4Lua: UE4에서 Lua 사용하기, NDC2019
 
IoT 개발자를 위한 Embedded C에서 TDD를 해보자
IoT 개발자를 위한 Embedded C에서 TDD를 해보자IoT 개발자를 위한 Embedded C에서 TDD를 해보자
IoT 개발자를 위한 Embedded C에서 TDD를 해보자
 
Chapter7~9 ppt
Chapter7~9 pptChapter7~9 ppt
Chapter7~9 ppt
 
프로젝트 관리 및 지켜야 할 사항들
프로젝트 관리 및 지켜야 할 사항들프로젝트 관리 및 지켜야 할 사항들
프로젝트 관리 및 지켜야 할 사항들
 
Windows reversing study_basic_7
Windows reversing study_basic_7Windows reversing study_basic_7
Windows reversing study_basic_7
 
Tdd ver.2
Tdd ver.2Tdd ver.2
Tdd ver.2
 
버전관리시스템 종류와 소개
버전관리시스템 종류와 소개버전관리시스템 종류와 소개
버전관리시스템 종류와 소개
 
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
 
[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기
[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기
[FEConf 2018] Front-End 프로젝트의 Test code 작성경험기
 

More from 진화 손

C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf진화 손
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf진화 손
 
C++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templatesC++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templates진화 손
 
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...진화 손
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions진화 손
 
C++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdfC++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdf진화 손
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types진화 손
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements진화 손
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library진화 손
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine진화 손
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules진화 손
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules진화 손
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)진화 손
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains진화 손
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers진화 손
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]진화 손
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts진화 손
 
C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>진화 손
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr진화 손
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields진화 손
 

More from 진화 손 (20)

C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf
 
C++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templatesC++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templates
 
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions
 
C++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdfC++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdf
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts
 
C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields
 

클린코드 16장

  • 1. 클린코드 스터디 16장. SerialDate 리팩토링 이데아게임즈 손진화
  • 2. 이 장의 내용 • org.jfree.date.SerialDate 클래스를 리팩토링 해보기 • 오리지널 코드 https://github.com/jfree/jcommon/tree/master/src/main/java/org/jfree/date
  • 3. 테스트 코드를 수행하자 • 존재하는 테스트 코드를 돌려서 모든 테스트 케이스를 성공적으로 통과하는지 확인 • 테스트 코드가 모든 기능들을 테스트 하는 지 확인 • Code Coverage Tool Java : Clover https://ko.atlassian.com/software/clover Cpp : gcov http://korea.gnu.org/manual/release/gcov/gcov_1.ko.html
  • 4. 코드 커버리지를 확인했더니… • 코드 커버리지가 50% 밖에 되지 않았다! • 모든 코드를 다 테스트 할 수 있도록 추가로 테스트 코드 작성 p484 • 새로 추가한 테스트 코드가 모두 성공할 수 있 도록 버그를 수정한다
  • 5. 본격적으로 리팩토링 시작 • 변경 이력 제거 [C1] p448 L1 변경 이력은 소스관리 툴에서 확인 가능하다 • 코드에 사용되는 언어 통일 [G1] p449 L67 java와 javadoc 으로 통일 • 클래스명 변경 [N1] [N2] 좀 더 서술적이고 추상 클래스에 맞는 이름으 로 변경
  • 6. 본격적으로 리팩토링 시작 • 구현 클래스에서만 사용하는 멤버변수를 구 현 클래스 안으로 이동 [G6] p450 L98 • 추상 클래스 안에 있는 구현 클래스 코드 제거 [G7] p466 L808 구현 클래스 생성 코드는 ABSTRACT FACTORY 로 분리 DACORATOR, SINGLETON 적용
  • 7. • 많은 수의 연관된 서브 클래스를 특정 그룹으 로 묶어 한번에 교체할 수 있도록 만든 디자인 패턴 http://jdm.kr/blog/192
  • 8. • 주어진 상황 및 용도에 따라 어떤 객체에 책임 을 덧붙이는 패턴으로, 기능 확장이 필요할 때 서브클래싱 대신 쓸 수 있는 유연한 대안이 될 수 있다 [링크]
  • 9. 본격적으로 리팩토링 시작 패턴들이 적용된 결과 p352~p353 • 요일 상수를 enum으로 변경 [J3] p450 L109 • 필요 없는 주석 삭제 [C3] p451 L139 코드만 봐도 충분히 의미가 파악된다 • 사용하지 않는 코드 제거 [G9] p451 L144
  • 10. 본격적으로 리팩토링 시작 • 멤버 변수를 private로 변경 p451 L144 • 변수는 사용하는 곳과 가까운 곳에 선언 [G10] p505 L434 • 용어를 사용하여 의미를 명확하게 한다 [N3] p452 L177 같은 의미를 가지는 수학적 용어로 이름 변경
  • 11. 본격적으로 리팩토링 시작 • 빈 기본 생성자 제거 [G12] p452 L213 어차피 컴파일러가 자동으로 생성해준다 • 리팩토링을 하면서 코드와 의미가 달라진 주 석 삭제 [C2] • 다른 조건으로 같은 행동을 하는 코드 묶음 [G5] p454 L259~L263 중복된 코드를 제거하라
  • 12. 본격적으로 리팩토링 시작 • 같은 개념을 가진 코드는 같은 곳에 위치하도 록 이동 [G13] p453 250 요일을 enum으로 만들면서 수정할 필요가 생 김 p356 • 클래스 외부에 선언된 enum에 대한 연산을 하고 있다. 이 기능을 enum내부로 이동 [G14] p456 L377 ~ p457 L426 달을 enum으로 만들면서 수정할 필요가 생김 p358
  • 13. 본격적으로 리팩토링 시작 • 모호한 표현을 제거하고 서술적인 표현으로 가독성을 높인다 [G16] p459 L495 p359 • 부적절한 static 표현 삭제 [G18] p461 L562 재정의 하지 않을 것이라는 보장이 없다 p360 • 임시 변수의 이름을 서술적으로 바꾼다 [G19] p461 L593 -> p360
  • 14. 본격적으로 리팩토링 시작 • 모호하게 해석되지 않도록 명확한 이름으로 변경 [N4] p361 • 숨겨진 논리적 의도성을 드러내라 [G22] p500 L247 추상 클래스와 연관 되어 있을 것 같은 동작이 구현클래스에 의존성을 가지고 있었다. 이를 메소드로 분리해 확실하게 드러낸다. p364
  • 15. 결과 코드 • 리팩토링을 하면서 계속 테스트 코드를 실행 하여 코드 품질을 유지하도록 한다 • https://github.com/ludwiggj/CleanCode/ tree/master/src/clean/code/chapter16/sol ution