├── .classpath ├── .gitignore ├── .idea ├── checkstyle-idea.xml ├── libraries │ └── com_bluecatcode_junit_junit_4_10_extended_1_0_1.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── README.md ├── Refactoring.iml └── src └── com └── kws ├── MethodClean ├── 6장캡쳐 │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 2.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ ├── 6.png │ ├── 7.png │ ├── 8.png │ ├── 9.png │ ├── Thumbs.db │ └── 메서드정리.png ├── MethodClean.sln ├── MethodClean.v11.suo ├── MethodClean │ ├── 1. 메서드 추출 │ │ ├── MethodMain.cs │ │ ├── Order.cs │ │ └── Program.cs │ ├── 2. 임시변수를 메서드 호출로 전환 │ │ └── MethodMain.cs │ ├── 3. 직관적 임시변수 사용 │ │ └── MethodMain.cs │ ├── 4. 임시변수 분리 │ │ └── MainMethod.cs │ ├── 5. 매개변수로의 값 대입 제거 │ │ └── MethodMain.cs │ ├── 6. 메서드를 메서드 객체로 전환 │ │ └── Account.cs │ ├── App.config │ ├── MethodClean.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── bin │ │ └── Debug │ │ │ ├── MethodClean.exe │ │ │ ├── MethodClean.exe.config │ │ │ ├── MethodClean.pdb │ │ │ ├── MethodClean.vshost.exe │ │ │ ├── MethodClean.vshost.exe.config │ │ │ └── MethodClean.vshost.exe.manifest │ └── obj │ │ └── Debug │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ ├── MethodClean.csproj.FileListAbsolute.txt │ │ ├── MethodClean.csprojResolveAssemblyReference.cache │ │ ├── MethodClean.exe │ │ ├── MethodClean.pdb │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs └── MethodCleanRepactoring │ ├── 1. 메서드 추출 │ ├── MethodMain.cs │ ├── Order.cs │ └── OrderList.cs │ ├── 2. 임시변수를 메서드 호출로 전환 │ └── MethodMain.cs │ ├── 3. 직관적 임시변수 사용 │ ├── 메서드 추출 사용 │ │ └── MethodMain.cs │ └── 직관적 임시변수 │ │ └── MethodMain.cs │ ├── 4. 임시변수 분리 │ └── MethodMain.cs │ ├── 5. 매개변수로의 값 대입 제거 │ └── MethodMain.cs │ ├── 6. 메서드를 메서드 객체로 전환 │ ├── Account.cs │ └── Gamma.cs │ ├── App.config │ ├── MethodCleanRepactoring.csproj │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── bin │ └── Debug │ │ ├── MethodCleanRepactoring.exe │ │ ├── MethodCleanRepactoring.exe.config │ │ └── MethodCleanRepactoring.pdb │ └── obj │ └── Debug │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── MethodCleanRepactoring.csproj.FileListAbsolute.txt │ ├── MethodCleanRepactoring.csprojResolveAssemblyReference.cache │ ├── MethodCleanRepactoring.exe │ ├── MethodCleanRepactoring.pdb │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs ├── eight ├── .gitignore ├── Log.java ├── Test8.java ├── eights │ ├── Customer.java │ └── Order.java ├── eleven │ ├── ArrayTest.java │ ├── Client.java │ ├── CommandMap.java │ ├── Course.java │ ├── Person.java │ └── VectorTest.java ├── fifteen │ ├── Employee.java │ ├── EmployeeType.java │ ├── Engineer.java │ ├── Manager.java │ └── Salesman.java ├── fives │ ├── ArrayTest.java │ └── Performance.java ├── fours │ └── Currency.java ├── fourteen │ ├── Employee.java │ └── Engineer.java ├── nine │ └── Test.java ├── ones │ ├── CappedRange.java │ └── IntRange.java ├── seven │ ├── Customer.java │ └── Order.java ├── six │ ├── Interval.java │ ├── IntervalWindow.java │ └── IntervalWindowChange.java ├── sixteen │ ├── Female.java │ ├── Male.java │ └── Person.java ├── ten │ └── Name.java ├── thirteen │ ├── BloodGroup.java │ └── Person.java ├── threes │ ├── Customer.java │ └── Order.java └── twos │ ├── Customer.java │ ├── OrderAfter.java │ └── OrderBefore.java ├── four ├── FileReaderTest4Unit.java └── FileReaderTester.java ├── nine ├── ConsolidateConditional.java ├── ConsolidateDuplicate.java ├── DecomposeConditional.java ├── IntroduceAssertion.java ├── IntroduceNullObject.java ├── RemoveControlFlag.java ├── ReplaceConditional.java └── ReplaceNestedConditional.java ├── one ├── after │ ├── Customer.java │ ├── ExamTest.java │ ├── Movie.java │ ├── Price.java │ └── Rental.java └── before │ ├── Customer.java │ ├── ExamTest.java │ ├── Movie.java │ └── Rental.java ├── seven ├── after │ ├── extractClass │ │ └── Person.java │ ├── hideDelegate │ │ ├── Department.java │ │ └── Person.java │ ├── inlineClass │ │ ├── Client.java │ │ ├── Person.java │ │ └── TelephoneNumber.java │ ├── introduceForeignMethod │ │ └── StartDate.java │ ├── moveField │ │ ├── Account.java │ │ └── AccountType.java │ ├── moveMethod │ │ ├── Account.java │ │ └── AccountType.java │ └── removeMiddleMan │ │ ├── Department.java │ │ └── Person.java ├── before │ ├── extractClass │ │ └── Person.java │ ├── hideDelegate │ │ ├── Department.java │ │ └── Person.java │ ├── inlineClass │ │ ├── Client.java │ │ ├── Person.java │ │ └── TelephoneNumber.java │ ├── introduceForeignMethod │ │ └── StartDate.java │ ├── moveField │ │ ├── Account.java │ │ └── AccountType.java │ ├── moveMethod │ │ ├── Account.java │ │ └── AccountType.java │ └── removeMiddleMan │ │ ├── Department.java │ │ └── Person.java └── test │ ├── extractClass │ └── PsersonTest.java │ ├── hideDelegate │ ├── AfterPersonTest.java │ └── BeforePersonTest.java │ ├── introduceForeignMethod │ └── StartDateTest.java │ ├── moveField │ └── AccountTest.java │ ├── moveMethod │ └── AccountTest.java │ └── removeMiddleMan │ ├── AfterPersonTest.java │ └── BeforePersonTest.java └── testFixture ├── data.txt └── empty.txt /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | .idea/compiler.xml 3 | .idea/copyright/ 4 | .idea/misc.xml 5 | .idea/workspace.xml 6 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/com_bluecatcode_junit_junit_4_10_extended_1_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Refactoring 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #리팩토링 코드 품질을 개선하는 객체지향 사고법 Study 2 | ----------------------------------------------------- 3 | - 스터디 기간 : 5/1 ~ 6/30 4 | - 스터디 장소 : 서울대 입구역 AZ Story 5 | - 스터디원 : 노휘겸 / 박민규 / 이돈일 / 이지훈 / 신민수 / 조아라 6 | - 보증금 : 20,000원 7 | - 스터디 룸비 : 20,000원 8 | - 한달 한번 결석 가능 9 | - 발표날 빠지면 영구 제명( 천재지변 / 경조사제외 ) 10 | - 자기 발표 부분 [Wiki](https://github.com/KWSStudy/Refactoring/wiki)에 정리 필 11 | - 스터디 목표 : - 12 | 13 | ## 스터디 진행 14 | ---------------------------------------------------- 15 | 5/8 16 | - [맛보기 예제 (이돈일)](https://github.com/KWSStudy/Refactoring/wiki/맛보기 예제) 17 | - [리팩토링개론 (이돈일)](https://github.com/KWSStudy/Refactoring/wiki/리팩토링개론) 18 | 19 | 5/15 20 | - [코드의 구린내 (이지훈)](https://github.com/KWSStudy/Refactoring/wiki/코드의 구린내) 21 | - [테스트 작성 (이지훈)](https://github.com/KWSStudy/Refactoring/wiki/테스트 작성) 22 | - [리팩토링 기법 카탈로그에 대해 (이지훈)](https://github.com/KWSStudy/Refactoring/wiki/리팩토링 기법 카탈로그) 23 | 24 | 5/22 25 | - [메서드 정리 (조아라)](https://github.com/KWSStudy/Refactoring/wiki/메서드 정리) 26 | 27 | 5/29 28 | - [객체 간의 기능 이동 (노휘겸)](https://github.com/KWSStudy/Refactoring/wiki/객체 간의 기능 이동) 29 | 30 | 6/5 31 | - [데이터 체계화 (신민수)](https://github.com/KWSStudy/Refactoring/wiki/데이터 체계화) 32 | 33 | 6/11(토) 34 | - [조건문 간결화 (이돈일)](https://github.com/KWSStudy/Refactoring/wiki/조건문 간결화) 35 | 36 | 6/19(토) 노휘겸 결 37 | - [메서드 호출 단순화 (박민규)](https://github.com/KWSStudy/Refactoring/wiki/메서드 호출 단순화) 38 | -------------------------------------------------------------------------------- /Refactoring.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 32 | 203 | 216 | 217 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/10.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/11.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/12.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/13.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/14.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/15.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/16.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/17.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/18.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/19.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/2.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/20.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/21.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/22.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/23.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/3.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/4.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/5.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/6.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/7.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/8.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/9.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/Thumbs.db -------------------------------------------------------------------------------- /src/com/kws/MethodClean/6장캡쳐/메서드정리.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/6장캡쳐/메서드정리.png -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MethodClean", "MethodClean\MethodClean.csproj", "{533D1E9E-33E7-4511-BC70-4AE37FBEB7B6}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MethodCleanRepactoring", "MethodCleanRepactoring\MethodCleanRepactoring.csproj", "{075A62C9-8794-4E0B-A2F6-FB18EE6665CA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {533D1E9E-33E7-4511-BC70-4AE37FBEB7B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {533D1E9E-33E7-4511-BC70-4AE37FBEB7B6}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {533D1E9E-33E7-4511-BC70-4AE37FBEB7B6}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {533D1E9E-33E7-4511-BC70-4AE37FBEB7B6}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {075A62C9-8794-4E0B-A2F6-FB18EE6665CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {075A62C9-8794-4E0B-A2F6-FB18EE6665CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {075A62C9-8794-4E0B-A2F6-FB18EE6665CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {075A62C9-8794-4E0B-A2F6-FB18EE6665CA}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean.v11.suo -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/1. 메서드 추출/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MethodClean.메서드_추출 9 | { 10 | public class MethodMain 11 | { 12 | static Order OrderVO = new Order(); 13 | private static MethodMain mgr = null; 14 | public MethodMain() 15 | { 16 | mgr = new MethodMain(); 17 | } 18 | /// 19 | /// 1. 선언 20 | /// 2. 출력 21 | /// 3. 조건문 22 | /// 4. 출력 23 | /// 24 | public static void PrintOwing() 25 | { 26 | IEnumerator enumGet = ((IEnumerable)OrderVO).GetEnumerator(); 27 | 28 | double outstanding = 0.0; 29 | 30 | Console.WriteLine("*****************"); 31 | Console.WriteLine("****고객외상*****"); 32 | Console.WriteLine("*****************"); 33 | 34 | while (enumGet.MoveNext()) 35 | { 36 | Order each = (Order)enumGet.Current; 37 | outstanding = each.getAmount(); 38 | } 39 | 40 | Console.WriteLine("고객명" + OrderVO.Name); 41 | Console.WriteLine("외상액" + outstanding); 42 | 43 | Console.ReadKey(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/1. 메서드 추출/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MethodClean 9 | { 10 | public class Order 11 | { 12 | public Order() 13 | { 14 | Name = "조아라"; 15 | Amount = 4000; 16 | } 17 | public String Name 18 | { 19 | get; 20 | set; 21 | } 22 | public double Amount 23 | { 24 | get; 25 | set; 26 | } 27 | 28 | internal double getAmount() 29 | { 30 | return Amount * 0.5; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/1. 메서드 추출/Program.cs: -------------------------------------------------------------------------------- 1 | using MethodClean.메서드_추출; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace MethodClean 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | MethodMain.PrintOwing(); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/2. 임시변수를 메서드 호출로 전환/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodClean.임시변수를_메서드_호출로_전환 8 | { 9 | class MethodMain 10 | { 11 | int Quantity; 12 | int ItemPrice; 13 | 14 | double getPrice() 15 | { 16 | int basePriece = Quantity * ItemPrice; 17 | double discountFactor; 18 | 19 | if (basePriece > 1000) discountFactor = 0.95; 20 | else discountFactor = 0.98; 21 | return basePriece * discountFactor; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/3. 직관적 임시변수 사용/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodClean.직관적_임시변수_사용 8 | { 9 | class MethodMain 10 | { 11 | int Quantity; 12 | int ItemPrice; 13 | double Price() 14 | { 15 | //결제액(price) = 총 구매액(base price) - 16 | //대량 구매 할인(quantity discount) + 배송비(shipping) 17 | return Quantity * ItemPrice - 18 | Math.Max(0, Quantity - 500) * ItemPrice * 0.05 + 19 | Math.Min(Quantity * ItemPrice * 0.1, 100.0); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/4. 임시변수 분리/MainMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodClean.임시변수_분리 8 | { 9 | class MainMethod 10 | { 11 | int PrimaryForce; 12 | int Mass; 13 | int Delay; 14 | double getDistanceTravelled(int pTime) 15 | { 16 | double result; 17 | double acc = PrimaryForce / Mass; //초기 가속도 저장 18 | int primaryTime = Math.Min(pTime, Delay); 19 | result = 0.5 * acc * primaryTime * primaryTime; 20 | int secondaryTime = pTime - Delay; 21 | if (secondaryTime > 0) 22 | { 23 | double primaryVel = acc * Delay; 24 | acc = (PrimaryForce + secondaryTime) / Mass; //두 번째 힘으로 생긴 가속 더한 값 저장 25 | result += primaryVel * secondaryTime + 0.5 * acc * secondaryTime * secondaryTime; 26 | } 27 | return result; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/5. 매개변수로의 값 대입 제거/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodClean._5._매개변수로의_값_대입_제거 8 | { 9 | class MethodMain 10 | { 11 | int discount(int pIntpuVal, int pQuantity, int pYearDate) 12 | { 13 | if (pIntpuVal > 50) pIntpuVal -= 2; 14 | if (pQuantity > 100) pIntpuVal -= 1; 15 | if (pYearDate > 10000) pIntpuVal -= 4; 16 | return pIntpuVal; 17 | } 18 | public static void main(String[] args) 19 | { 20 | int x = 5; 21 | triple(x); 22 | Console.WriteLine("triple메서드 실행 후 x 값 : " + x); 23 | } 24 | 25 | private static void triple(int pArg) 26 | { 27 | pArg = pArg * 3; 28 | Console.WriteLine("triple메서드 실행 안 x 값 : " + pArg); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/6. 메서드를 메서드 객체로 전환/Account.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodClean._6._메서드를_메서드_객체로_전환 8 | { 9 | public class Account 10 | { 11 | int gamma(int pInpuVal, int pQuantity, int pYearDate) 12 | { 13 | int importantValue1 = (pInpuVal * pQuantity) + Delta(); 14 | int importantValue2 = (pInpuVal * pYearDate) + 100; 15 | if ((pYearDate - importantValue1) > 100) 16 | importantValue2 -= 20; 17 | int importantValue3 = importantValue2 + 7; 18 | 19 | return importantValue3 - 2 * importantValue1; 20 | } 21 | 22 | private int Delta() 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/MethodClean.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {533D1E9E-33E7-4511-BC70-4AE37FBEB7B6} 8 | Exe 9 | Properties 10 | MethodClean 11 | MethodClean 12 | v4.6 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 65 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다. 6 | // 어셈블리와 관련된 정보를 수정하려면 7 | // 이 특성 값을 변경하십시오. 8 | [assembly: AssemblyTitle("MethodClean")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MethodClean")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오. 20 | [assembly: ComVisible(false)] 21 | 22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. 23 | [assembly: Guid("75980bd6-edd1-40b5-95df-1ad174b8ee9e")] 24 | 25 | // 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. 26 | // 27 | // 주 버전 28 | // 부 버전 29 | // 빌드 번호 30 | // 수정 버전 31 | // 32 | // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로 33 | // 지정되도록 할 수 있습니다. 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.exe -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.pdb -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.vshost.exe -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.vshost.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/bin/Debug/MethodClean.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/MethodClean.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | c:\users\ara\documents\visual studio 2012\Projects\MethodClean\MethodClean\bin\Debug\MethodClean.exe.config 2 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodClean\bin\Debug\MethodClean.exe 3 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodClean\bin\Debug\MethodClean.pdb 4 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodClean\obj\Debug\MethodClean.csprojResolveAssemblyReference.cache 5 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodClean\obj\Debug\MethodClean.exe 6 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodClean\obj\Debug\MethodClean.pdb 7 | C:\Users\Ara\Desktop\Refactoring\MethodClean\MethodClean\bin\Debug\MethodClean.exe.config 8 | C:\Users\Ara\Desktop\Refactoring\MethodClean\MethodClean\obj\Debug\MethodClean.exe 9 | C:\Users\Ara\Desktop\Refactoring\MethodClean\MethodClean\obj\Debug\MethodClean.pdb 10 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/MethodClean.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/obj/Debug/MethodClean.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/MethodClean.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/obj/Debug/MethodClean.exe -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/MethodClean.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/obj/Debug/MethodClean.pdb -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodClean/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodClean/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/1. 메서드 추출/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MethodCleanRepactoring.메서드_추출 9 | { 10 | public class MethodMain 11 | { 12 | static OrderList OrderList = new OrderList(); 13 | private static MethodMain mgr = null; 14 | public MethodMain() 15 | { 16 | mgr = new MethodMain(); 17 | } 18 | public static void PrintOwing(double pPreviousAmount) 19 | { 20 | PrintBanner(); 21 | double outstanding = getOutsstanding(pPreviousAmount * 1.2); 22 | PrintDetails(outstanding); 23 | Console.ReadKey(); 24 | } 25 | /// 26 | /// 지역변수를 다시 대입 27 | /// Step1. 상위 계층의 지역변수가 이 메서드 안에서만 쓰이기 때문에 28 | /// Step2. 지역변수를 추출한 코드에서만 선언. 29 | /// Step3. 반환값의 이름 변경 30 | /// 31 | /// 32 | /// 33 | /// 34 | private static double getOutsstanding(double pInitalValue) 35 | { 36 | double resultAmount = pInitalValue; 37 | IEnumerator enumGet = ((IEnumerable)OrderList).GetEnumerator(); 38 | 39 | while (enumGet.MoveNext()) 40 | { 41 | Order each = (Order)enumGet.Current; 42 | resultAmount = each.getAmount(); 43 | } 44 | return resultAmount; 45 | } 46 | /// 47 | /// 지역변수 사용 (읽히기만 할때) 48 | /// 49 | /// 50 | private static void PrintDetails(double outstanding) 51 | { 52 | foreach (Order pOrder in OrderList) 53 | { 54 | Console.WriteLine("고객명" + pOrder.Name); 55 | Console.WriteLine("외상액" + outstanding); 56 | } 57 | } 58 | /// 59 | /// 지역변수 사용 안함(제일 간단한 구조) 60 | /// 61 | private static void PrintBanner() 62 | { 63 | Console.WriteLine("*****************"); 64 | Console.WriteLine("****고객외상*****"); 65 | Console.WriteLine("*****************"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/1. 메서드 추출/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MethodCleanRepactoring 9 | { 10 | public class Order 11 | { 12 | public Order() 13 | { 14 | 15 | 16 | } 17 | public String Name 18 | { 19 | get; 20 | set; 21 | } 22 | public double Amount 23 | { 24 | get; 25 | set; 26 | } 27 | 28 | internal double getAmount() 29 | { 30 | return Amount * 0.5; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/1. 메서드 추출/OrderList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring 8 | { 9 | public class OrderList : List 10 | { 11 | public OrderList() 12 | { 13 | Order order = new Order(); 14 | order.Name = "조아라"; 15 | order.Amount = 4000; 16 | this.Add(order); 17 | 18 | order = new Order(); 19 | order.Name = "홍길동"; 20 | order.Amount = 5000; 21 | this.Add(order); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/2. 임시변수를 메서드 호출로 전환/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring.임시변수를_메서드_호출로_전환 8 | { 9 | class MethodMain 10 | { 11 | int Quantity; 12 | int ItemPrice; 13 | 14 | double getPrice() 15 | { 16 | return basePrice() * DiscountFactor(); 17 | } 18 | 19 | private double DiscountFactor() 20 | { 21 | if (basePrice() > 1000) return 0.95; 22 | else return 0.98; 23 | } 24 | 25 | private int basePrice() 26 | { 27 | return Quantity * ItemPrice; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/3. 직관적 임시변수 사용/메서드 추출 사용/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring.직관적_임시변수_사용.메서드_추출_사용 8 | { 9 | class MethodMain 10 | { 11 | int Quantity; 12 | int ItemPrice; 13 | 14 | double Price() 15 | { 16 | //결제액(price) = 총 구매액(base price) - 17 | //대량 구매 할인(quantity discount) + 배송비(shipping) 18 | return basePrice() - quantityDiscount() + shipping(); 19 | } 20 | 21 | private double shipping() 22 | { 23 | return Math.Min(Quantity * ItemPrice * 0.1, 100.0); 24 | } 25 | 26 | private double quantityDiscount() 27 | { 28 | return Math.Max(0, Quantity - 500) * ItemPrice * 0.05; 29 | } 30 | 31 | private int basePrice() 32 | { 33 | return Quantity * ItemPrice; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/3. 직관적 임시변수 사용/직관적 임시변수/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring.직관적_임시변수_사용 8 | { 9 | class MethodMain 10 | { 11 | int Quantity; 12 | int ItemPrice; 13 | double Price() 14 | { 15 | //결제액(price) = 총 구매액(base price) - 16 | //대량 구매 할인(quantity discount) + 배송비(shipping) 17 | double basePrice = Quantity * ItemPrice; 18 | double quantityDiscount = Math.Max(0, Quantity - 500) * ItemPrice * 0.05; 19 | double shipping = Math.Min(basePrice * 0.1, 100.0); 20 | return basePrice - quantityDiscount + shipping; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/4. 임시변수 분리/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring._4._임시변수_분리 8 | { 9 | class MethodMain 10 | { 11 | int PrimaryForce; 12 | int Mass; 13 | int Delay; 14 | /// 15 | /// 해기스가 이동한 거리 계산 16 | /// 17 | /// 18 | /// 19 | double getDistanceTravelled(int pTime) 20 | { 21 | double result; 22 | double primaryAcc = PrimaryForce / Mass; 23 | int primaryTime = Math.Min(pTime, Delay); 24 | result = 0.5 * primaryAcc * primaryTime * primaryTime; 25 | int secondaryTime = pTime - Delay; 26 | if (secondaryTime > 0) 27 | { 28 | double primaryVel = primaryAcc * Delay; 29 | double secondaryAcc = (PrimaryForce + secondaryTime) / Mass; 30 | result += primaryVel * secondaryTime + 0.5 * secondaryAcc * secondaryTime * secondaryTime; 31 | } 32 | return result; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/5. 매개변수로의 값 대입 제거/MethodMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring._5._매개변수로의_값_대입_제거 8 | { 9 | class MethodMain 10 | { 11 | int discount(int pIntpuVal, int pQuantity, int pYearDate) 12 | { 13 | int result = pIntpuVal; 14 | if (pIntpuVal > 50) result -= 2; 15 | if (pQuantity > 100) result -= 1; 16 | if (pYearDate > 10000) result -= 4; 17 | return result; 18 | } 19 | 20 | public static void main(String[] args) 21 | { 22 | int x = 5; 23 | triple(x); 24 | Console.WriteLine("triple메서드 실행 후 x 값 : " + x); 25 | } 26 | 27 | private static void triple(int pArg) 28 | { 29 | pArg = pArg * 3; 30 | Console.WriteLine("triple메서드 실행 안 x 값 : " + pArg); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/6. 메서드를 메서드 객체로 전환/Account.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring._6._메서드를_메서드_객체로_전환 8 | { 9 | public class Account 10 | { 11 | int gamma(int pInpuVal, int pQuantity, int pYearDate) 12 | { 13 | return new Gamma(this, pInpuVal, pQuantity, pYearDate).Compute(); 14 | } 15 | internal int Delta() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/6. 메서드를 메서드 객체로 전환/Gamma.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring._6._메서드를_메서드_객체로_전환 8 | { 9 | public class Gamma 10 | { 11 | private readonly Account _Account; 12 | private int inputVal; 13 | private int Quantity; 14 | private int YearToDate; 15 | private int ImportantValue1; 16 | private int ImportantValue2; 17 | private int ImportantValue3; 18 | 19 | public Gamma(Account pSource, int pInputpValArg, int pQuantity, int pYearToDateArg) 20 | { 21 | _Account = pSource; 22 | inputVal = pInputpValArg; 23 | Quantity = pQuantity; 24 | YearToDate = pYearToDateArg; 25 | } 26 | public int Compute() 27 | { 28 | ImportantValue1 = (inputVal * Quantity) + _Account.Delta(); 29 | ImportantValue2 = (inputVal * YearToDate) + 100; 30 | importantThing(); 31 | int ImportantValue3 = ImportantValue2 * 7; 32 | return ImportantValue3 - 2 * ImportantValue1; 33 | } 34 | 35 | private void importantThing() 36 | { 37 | if ((YearToDate - ImportantValue1) > 100) 38 | ImportantValue2 -= 20; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/MethodCleanRepactoring.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {075A62C9-8794-4E0B-A2F6-FB18EE6665CA} 8 | Exe 9 | Properties 10 | MethodCleanRepactoring 11 | MethodCleanRepactoring 12 | v4.6 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MethodCleanRepactoring 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다. 6 | // 어셈블리와 관련된 정보를 수정하려면 7 | // 이 특성 값을 변경하십시오. 8 | [assembly: AssemblyTitle("MethodCleanRepactoring")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MethodCleanRepactoring")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오. 20 | [assembly: ComVisible(false)] 21 | 22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. 23 | [assembly: Guid("1cc355e8-8571-4aa2-8869-7a98c67b22f1")] 24 | 25 | // 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. 26 | // 27 | // 주 버전 28 | // 부 버전 29 | // 빌드 번호 30 | // 수정 버전 31 | // 32 | // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로 33 | // 지정되도록 할 수 있습니다. 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/bin/Debug/MethodCleanRepactoring.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/bin/Debug/MethodCleanRepactoring.exe -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/bin/Debug/MethodCleanRepactoring.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/bin/Debug/MethodCleanRepactoring.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/bin/Debug/MethodCleanRepactoring.pdb -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/MethodCleanRepactoring.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodCleanRepactoring\obj\Debug\MethodCleanRepactoring.csprojResolveAssemblyReference.cache 2 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodCleanRepactoring\bin\Debug\MethodCleanRepactoring.exe.config 3 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodCleanRepactoring\bin\Debug\MethodCleanRepactoring.exe 4 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodCleanRepactoring\bin\Debug\MethodCleanRepactoring.pdb 5 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodCleanRepactoring\obj\Debug\MethodCleanRepactoring.exe 6 | C:\Users\Ara\documents\visual studio 2012\Projects\MethodClean\MethodCleanRepactoring\obj\Debug\MethodCleanRepactoring.pdb 7 | -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/MethodCleanRepactoring.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/MethodCleanRepactoring.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/MethodCleanRepactoring.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/MethodCleanRepactoring.exe -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/MethodCleanRepactoring.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/MethodCleanRepactoring.pdb -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/MethodClean/MethodCleanRepactoring/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /src/com/kws/eight/.gitignore: -------------------------------------------------------------------------------- 1 | /IntRange.java 2 | /CappedRange.java 3 | /Customer.java 4 | /OrderAfter.java 5 | /OrderBefore.java 6 | /one/ 7 | /two/ 8 | -------------------------------------------------------------------------------- /src/com/kws/eight/Log.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Log { 6 | // true log show , false log hide 7 | public static final boolean LOGFLAG = true; 8 | public static final boolean LOGLISTFLAG = true; 9 | 10 | public static void systemLog(StringBuffer str){ 11 | if(LOGFLAG){ 12 | System.out.println(str); 13 | } 14 | } 15 | 16 | public static void systemLog(String str){ 17 | if(LOGFLAG){ 18 | System.out.println(str); 19 | } 20 | } 21 | 22 | public static void systemLog(String str, int value){ 23 | if(LOGFLAG){ 24 | System.out.println(str + value); 25 | } 26 | } 27 | 28 | public static void systemLog(String str, long value){ 29 | if(LOGFLAG){ 30 | System.out.println(str + value); 31 | } 32 | } 33 | 34 | public static void systemLog(String str, String value){ 35 | if(LOGFLAG){ 36 | System.out.println(str + value); 37 | } 38 | } 39 | 40 | public static void systemLog(String str,ArrayList value){ 41 | if(LOGLISTFLAG){ 42 | int val = value.size(); 43 | for(int i = 0; i < val; i++){ 44 | System.out.println(str + " =" + i + " : " + value.get(val)); 45 | } 46 | } 47 | } 48 | 49 | public static void systemLog(ArrayList value){ 50 | if(LOGLISTFLAG){ 51 | int val = value.size(); 52 | for(int i = 0; i < val; i++){ 53 | System.out.println(i + " : " + value.get(val)); 54 | } 55 | } 56 | } 57 | 58 | public static void systemLog(String[] value){ 59 | if(LOGLISTFLAG){ 60 | int val = value.length; 61 | for(int i = 0; i < val; i++){ 62 | System.out.println(i + " : " + value[val]); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/kws/eight/Test8.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight; 2 | 3 | public class Test8 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/kws/eight/eights/Customer.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eights; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Customer { 7 | private static Set orders = new HashSet(); 8 | 9 | void addOrder(Order arg){ 10 | arg.setCustomer(this); 11 | } 12 | 13 | Set friendOrders(){ 14 | return orders; 15 | } 16 | 17 | public int getDiscount() { 18 | // TODO Auto-generated method stub 19 | return 0; 20 | } 21 | 22 | double getPriceFor(Order order){ 23 | return order.getDiscountedPrice(this); 24 | } 25 | 26 | public static Set getInstance() { 27 | // TODO Auto-generated method stub 28 | return orders; 29 | } 30 | 31 | public boolean containsOrder(Order order) { 32 | // TODO Auto-generated method stub 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/kws/eight/eights/Order.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eights; 2 | 3 | import java.util.Iterator; 4 | 5 | public class Order { 6 | private Customer customers; 7 | 8 | // public Customer getCustomer() { 9 | // return customers; 10 | // } 11 | 12 | public void setCustomer(Customer arg) { 13 | // this.customer = customer; 14 | if (customers != null) 15 | customers.friendOrders().remove(this); 16 | customers = arg; 17 | if (customers != null) 18 | customers.friendOrders().add(this); 19 | } 20 | 21 | double getDiscountedPrice(Customer customer) { 22 | return getGrossPrice() * (1 - customer.getDiscount()); 23 | } 24 | 25 | private int getGrossPrice() { 26 | // TODO Auto-generated method stub 27 | return 0; 28 | } 29 | 30 | @SuppressWarnings("rawtypes") 31 | Customer getCustomer() { 32 | Iterator iter = Customer.getInstance().iterator(); 33 | while (iter.hasNext()) { 34 | Customer each = (Customer) iter.next(); 35 | if (each.containsOrder(this)) 36 | return each; 37 | } 38 | return null; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/com/kws/eight/eleven/ArrayTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eleven; 2 | 3 | public class ArrayTest { 4 | 5 | private String[] skills; 6 | 7 | // public String[] getSkills() { 8 | // return skills; 9 | // } 10 | public String[] getSkills() { 11 | String[] result = new String[skills.length]; 12 | System.arraycopy(skills, 0, result, 0, skills.length); 13 | return result; 14 | } 15 | 16 | // public void setSkills(String[] arg) { 17 | // this.skills = skills; 18 | // } 19 | 20 | public void setSkill(int index, String skill) { 21 | skills = new String[skill.length()]; 22 | skills[index] = skill; 23 | } 24 | 25 | public void setSkills(String[] arg) { 26 | skills = new String[skills.length]; 27 | for(int i = 0; i < skills.length; i++){ 28 | setSkill(i,arg[i]); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/com/kws/eight/eleven/Client.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eleven; 2 | 3 | import java.util.HashSet; 4 | import java.util.Iterator; 5 | import java.util.Set; 6 | 7 | import org.junit.Assert; 8 | 9 | 10 | public class Client { 11 | 12 | @SuppressWarnings({ "rawtypes", "unchecked" }) 13 | public static void main(String[] args) { 14 | 15 | Person kent = new Person(); 16 | 17 | Set s = new HashSet(); 18 | 19 | // before 20 | // s.add(new Course("스몰토크 프로그래밍", false)); 21 | // s.add(new Course("싱글몰드 위스키 음미하기", true)); 22 | 23 | // after 24 | kent.addCourse(new Course("스몰토크 프로그래밍", false)); 25 | kent.addCourse(new Course("싱글몰드 위스키 음미하기", true)); 26 | 27 | // kent.setCourse(s); 28 | kent.initalizeCourse(s); 29 | 30 | // Assert.assertEquals(2, kent.getCourse().size()); 31 | System.out.println("---------------------------------"); 32 | Course refact = new Course("리팩토링", true); 33 | 34 | kent.getCourse().add(refact); 35 | 36 | // before 37 | // kent.getCourse().add(new Course("지독한 빈정거림", false)); 38 | // after 39 | kent.addCourse(new Course("지독한 빈정거림", false)); 40 | 41 | // Assert.assertEquals(4, kent.getCourse().size()); 42 | 43 | kent.getCourse().remove(refact); 44 | 45 | // Assert.assertEquals(3, kent.getCourse().size()); 46 | 47 | // System.out.println(kent.getCourse().size()); 48 | 49 | //고급과정 50 | Iterator iter = kent.getCourse().iterator(); 51 | 52 | int count = 0; 53 | 54 | while(iter.hasNext()){ 55 | Course each = (Course) iter.next(); 56 | if(each.isAdvanced()){ 57 | count++; 58 | } 59 | } 60 | 61 | System.out.println(count); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/kws/eight/eleven/CommandMap.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eleven; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Map.Entry; 6 | import java.util.Set; 7 | 8 | public class CommandMap { 9 | Map map = new HashMap(); 10 | 11 | public Object get(String key){ 12 | return map.get(key); 13 | } 14 | 15 | public void put(String key, Object value){ 16 | map.put(key, value); 17 | } 18 | 19 | public Object remove(String key){ 20 | return map.remove(key); 21 | } 22 | 23 | public boolean containsKey(String key){ 24 | return map.containsKey(key); 25 | } 26 | 27 | public boolean containsValue(Object value){ 28 | return map.containsValue(value); 29 | } 30 | 31 | public void clear(){ 32 | map.clear(); 33 | } 34 | 35 | public Set> entrySet(){ 36 | return map.entrySet(); 37 | } 38 | 39 | public Set keySet(){ 40 | return map.keySet(); 41 | } 42 | 43 | public boolean isEmpty(){ 44 | return map.isEmpty(); 45 | } 46 | 47 | public void putAll(Map m){ 48 | map.putAll(m); 49 | } 50 | 51 | public Map getMap(){ 52 | return map; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/kws/eight/eleven/Course.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eleven; 2 | 3 | public class Course { 4 | 5 | private String name; 6 | private boolean isA; 7 | 8 | public Course(String name, boolean isAdvanced){ 9 | this.name = name; 10 | this.isA = isAdvanced; 11 | } 12 | 13 | public boolean isAdvanced(){ 14 | return true; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/kws/eight/eleven/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eleven; 2 | 3 | import java.util.Collections; 4 | import java.util.HashSet; 5 | import java.util.Iterator; 6 | import java.util.Set; 7 | 8 | import junit.framework.Assert; 9 | 10 | public class Person { 11 | 12 | // private Set course; 13 | @SuppressWarnings("rawtypes") 14 | private Set course = new HashSet(); 15 | 16 | 17 | // @SuppressWarnings("unchecked") 18 | // public Set getCourse() { 19 | // return Collections.unmodifiableSet(course); 20 | // unmodifiableSet 메소드는 지정된 세트의 변경 불가능한 뷰를 돌려줍니다. 21 | // } 22 | 23 | // public void setCourse(Set course) { 24 | // this.course = course; 25 | // } 26 | 27 | public Set getCourse() { 28 | return course; 29 | } 30 | 31 | // setCourses 32 | @SuppressWarnings("rawtypes") 33 | public void initalizeCourse(Set arg) { 34 | // Assert.isTrue(course.isEmpty()); 35 | Iterator iter = arg.iterator(); 36 | while(iter.hasNext()){ 37 | addCourse((Course) iter.next()); 38 | } 39 | } 40 | 41 | // 메서드 복사기능 42 | // 초기화하려고 원소를 추가할때 추가 기능이 확실히 필요 없다면 다음과 같이 루프를 삭제하고 addAll메서드를 사용. 43 | // public void initalizeCourse(Set arg) { 44 | // Assert.isTrue(course.isEmpty()); 45 | // course.addAll(arg); 46 | // } 47 | 48 | @SuppressWarnings("unchecked") 49 | public void addCourse(Course arg){ 50 | course.add(arg); 51 | } 52 | 53 | public void removeCourse(Course arg){ 54 | course.remove(arg); 55 | } 56 | 57 | 58 | @SuppressWarnings("rawtypes") 59 | int numberOfAdvancedCourse(Person person){ 60 | Iterator iter = person.getCourse().iterator(); 61 | 62 | int count = 0; 63 | 64 | while(iter.hasNext()){ 65 | Course each = (Course) iter.next(); 66 | if(each.isAdvanced()){ 67 | count++; 68 | } 69 | } 70 | 71 | return count; 72 | } 73 | 74 | int numberOfCourse(){ 75 | return course.size(); 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /src/com/kws/eight/eleven/VectorTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.eleven; 2 | 3 | import java.util.Enumeration; 4 | import java.util.Vector; 5 | 6 | public class VectorTest { 7 | 8 | private Vector course; 9 | 10 | public Vector getCourse() { 11 | return course; 12 | } 13 | 14 | public void setCourse(Vector course) { 15 | this.course = course; 16 | } 17 | 18 | @SuppressWarnings("unchecked") 19 | public void addCourse(Course arg){ 20 | course.addElement(arg); 21 | } 22 | 23 | public void removeCourse(Course arg){ 24 | course.removeElement(arg); 25 | } 26 | 27 | @SuppressWarnings("rawtypes") 28 | public void initalizeCourse(Vector arg) { 29 | // Assert.isTrue(course.isEmpty()); 30 | Enumeration iter = arg.elements(); 31 | while(iter.hasMoreElements()){ 32 | addCourse((Course) iter.nextElement()); 33 | } 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/com/kws/eight/fifteen/Employee.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fifteen; 2 | 3 | public class Employee { 4 | private EmployeeType type; 5 | 6 | // static final int ENGINEER = 0; 7 | // static final int SALESMAN = 1; 8 | // static final int MANAGER = 2; 9 | 10 | private int monthlySalary = 100; 11 | private int commission = 10; 12 | private int bonus = 30; 13 | 14 | public Employee(EmployeeType arg) { 15 | this.type = arg; 16 | } 17 | 18 | int getType(){ 19 | return type.getTypeCode(); 20 | } 21 | 22 | public void setType(int arg) { 23 | type = EmployeeType.newType(arg); 24 | } 25 | 26 | int payAmount(int arg) { 27 | switch (arg) { 28 | case EmployeeType.ENGINEER: 29 | return monthlySalary; 30 | case EmployeeType.SALESMAN: 31 | return monthlySalary + commission; 32 | case EmployeeType.MANAGER: 33 | return monthlySalary + bonus; 34 | default: 35 | throw new IllegalArgumentException("Incorrect"); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/kws/eight/fifteen/EmployeeType.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fifteen; 2 | 3 | abstract class EmployeeType { 4 | 5 | static final int ENGINEER = 0; 6 | static final int SALESMAN = 1; 7 | static final int MANAGER = 2; 8 | 9 | abstract int getTypeCode(); 10 | 11 | static EmployeeType newType(int code){ 12 | switch (code) { 13 | case ENGINEER: 14 | return new Engineer(); 15 | case SALESMAN: 16 | return new Salesman(); 17 | case MANAGER: 18 | return new Manager(); 19 | default: 20 | throw new IllegalArgumentException("사원 부호가 잘못됨."); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/kws/eight/fifteen/Engineer.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fifteen; 2 | 3 | public class Engineer extends EmployeeType{ 4 | int getTypeCode() { 5 | return EmployeeType.ENGINEER; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/kws/eight/fifteen/Manager.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fifteen; 2 | 3 | public class Manager extends EmployeeType{ 4 | int getTypeCode() { 5 | return EmployeeType.MANAGER; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/kws/eight/fifteen/Salesman.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fifteen; 2 | 3 | public class Salesman extends EmployeeType{ 4 | int getTypeCode() { 5 | return EmployeeType.SALESMAN; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/kws/eight/fives/ArrayTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fives; 2 | 3 | public class ArrayTest { 4 | 5 | public static void main(String[] args) { 6 | 7 | // String[] data = new String[3]; 8 | // 9 | // data[0] = "Live"; 10 | // data[1] = "15"; 11 | // 12 | // String name = data[0]; 13 | // int wins = Integer.parseInt(data[1]); 14 | 15 | Performance row = new Performance(); 16 | 17 | row.setName("LiverPool"); 18 | row.setWins("15"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/kws/eight/fives/Performance.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fives; 2 | 3 | public class Performance { 4 | 5 | private String name; 6 | private String wings; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String arg) { 13 | this.name = arg; 14 | } 15 | 16 | public int getWins(){ 17 | return Integer.parseInt(wings); 18 | } 19 | 20 | public void setWins(String arg){ 21 | this.wings = arg; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/kws/eight/fours/Currency.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fours; 2 | 3 | public class Currency { 4 | private String code; 5 | 6 | public String getCode() { 7 | return code; 8 | } 9 | 10 | private Currency(String code){ 11 | this.code = code; 12 | } 13 | 14 | // public boolean equals(Object arg){ 15 | // if(!(arg instanceof Currency)) return false; 16 | // Currency other = (Currency)arg; 17 | // return (this.getCode().equals(other.getCode())); 18 | // } 19 | 20 | public int hashCode(){ 21 | return this.code.hashCode(); 22 | } 23 | 24 | public static void main(String[] args) { 25 | System.out.println(new Currency("USD").equals(new Currency("USD"))); // false; 26 | // System.out.println(new Currency("USD").getCode().equals(new Currency("USD").getCode())); // true; 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/kws/eight/fourteen/Employee.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fourteen; 2 | 3 | abstract class Employee { 4 | private int type; 5 | 6 | static final int ENGINEER = 0; 7 | static final int SALESMAN = 1; 8 | static final int MANAGER = 2; 9 | 10 | static Employee create(int arg) { 11 | switch (arg) { 12 | case ENGINEER: 13 | return new Engineer(ENGINEER); 14 | case SALESMAN: 15 | // return new Salesman(); 16 | case MANAGER: 17 | // return new Manage(); 18 | default: 19 | throw new IllegalArgumentException("Incorrect"); 20 | } 21 | } 22 | 23 | public Employee(int arg) { 24 | this.type = arg; 25 | } 26 | 27 | // public int getType() { 28 | // return type; 29 | // } 30 | 31 | abstract int getType(); 32 | 33 | public void setType(int type) { 34 | this.type = type; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/com/kws/eight/fourteen/Engineer.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.fourteen; 2 | 3 | public class Engineer extends Employee{ 4 | 5 | public Engineer(int arg) { 6 | super(arg); 7 | } 8 | 9 | public int getType(){ 10 | return Employee.ENGINEER; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/com/kws/eight/nine/Test.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.nine; 2 | 3 | public class Test { 4 | 5 | 6 | double potentiaEnergy(double mass, double height){ 7 | return mass * 981 * height; 8 | } 9 | 10 | static final double GRAVITATION_CONSTANT = 9.81; 11 | 12 | double potentiaEnergys(double mass, double height){ 13 | return mass * GRAVITATION_CONSTANT * height; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/kws/eight/ones/CappedRange.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.ones; 2 | 3 | public class CappedRange extends IntRange{ 4 | private int _cap; 5 | 6 | CappedRange(int low, int high,int cap) { 7 | super(low, high); 8 | this._cap = cap; 9 | } 10 | 11 | public int get_cap() { 12 | return _cap; 13 | } 14 | 15 | public void set_cap(int _cap) { 16 | this._cap = _cap; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/com/kws/eight/ones/IntRange.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.ones; 2 | 3 | public class IntRange { 4 | private int _low,_high; 5 | 6 | boolean includes(int arg){ 7 | return arg >= get_low() && arg <= get_high(); 8 | } 9 | 10 | void grow(int factor){ 11 | this._high = get_high() * factor; 12 | } 13 | 14 | IntRange(int low, int high){ 15 | initialize(low, high); 16 | } 17 | 18 | private void initialize(int low, int high){ 19 | this._low = low; 20 | this._high = high; 21 | } 22 | 23 | public int get_low() { 24 | return _low; 25 | } 26 | 27 | public void set_low(int _low) { 28 | this._low = _low; 29 | } 30 | 31 | public int get_high() { 32 | return _high; 33 | } 34 | 35 | public void set_high(int _high) { 36 | this._high = _high; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/kws/eight/seven/Customer.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.seven; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Customer { 7 | @SuppressWarnings("rawtypes") 8 | private Set orders = new HashSet(); 9 | 10 | @SuppressWarnings("rawtypes") 11 | Set friendOrders(){ 12 | /*연결을 변경할 때 Order에 의해서만 사용되어야 함.*/ 13 | return orders; 14 | } 15 | 16 | void addOrder(Order arg){ 17 | arg.addCustomer(this); 18 | } 19 | 20 | void removeOrder(Order arg){ 21 | arg.removeCustomer(this); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/kws/eight/seven/Order.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.seven; 2 | 3 | import java.util.Set; 4 | 5 | public class Order { 6 | Customer customers; 7 | 8 | public Customer getCustomer() { 9 | return customers; 10 | } 11 | 12 | @SuppressWarnings("unchecked") 13 | public void setCustomer(Customer arg) { 14 | //this.customer = customer; 15 | if(customers != null) customers.friendOrders().remove(this); 16 | customers = arg; 17 | if(customers != null) customers.friendOrders().add(this); 18 | } 19 | 20 | //연결제어 메서드 21 | @SuppressWarnings({ "unchecked", "rawtypes" }) 22 | void addCustomer(Customer arg){ 23 | arg.friendOrders().add(this); 24 | ((Set) customers).add(arg); 25 | // customers.friendOrders().add(arg); 26 | } 27 | 28 | @SuppressWarnings("rawtypes") 29 | void removeCustomer(Customer arg){ 30 | arg.friendOrders().remove(this); 31 | ((Set) customers).remove(arg); 32 | // customers.friendOrders().remove(arg); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/kws/eight/six/Interval.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.six; 2 | 3 | import java.util.Observable; 4 | 5 | public class Interval extends Observable{ 6 | private String end = "0"; 7 | private String start = "0"; 8 | private String length = "0"; 9 | 10 | String getEnd(){ 11 | return end; 12 | } 13 | 14 | void setEnd(String arg){ 15 | this.end = arg; 16 | setChanged(); 17 | notifyObservers(); 18 | } 19 | 20 | String getStart(){ 21 | return start; 22 | } 23 | 24 | void setStart(String arg){ 25 | this.start = arg; 26 | setChanged(); 27 | notifyObservers(); 28 | } 29 | 30 | String getLength(){ 31 | return length; 32 | } 33 | 34 | void setLength(String arg){ 35 | this.length = arg; 36 | setChanged(); 37 | notifyObservers(); 38 | } 39 | 40 | void calculateLength(){ 41 | try{ 42 | int start = Integer.parseInt(getStart()); 43 | int end = Integer.parseInt(getEnd()); 44 | int length = end - start; 45 | setLength(String.valueOf(length)); 46 | }catch(NumberFormatException e){ 47 | throw new RuntimeException("잘못된 숫자 형식 에러"); 48 | } 49 | } 50 | 51 | void calculateEnd(){ 52 | try{ 53 | int start = Integer.parseInt(getStart()); 54 | int length = Integer.parseInt(getLength()); 55 | int end = start + length; 56 | setEnd(String.valueOf(end)); 57 | }catch(NumberFormatException e){ 58 | throw new RuntimeException("잘못된 숫자 형식 에러"); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/kws/eight/six/IntervalWindow.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.six; 2 | 3 | import java.awt.Frame; 4 | import java.awt.TextField; 5 | import java.awt.event.FocusAdapter; 6 | import java.awt.event.FocusEvent; 7 | 8 | @SuppressWarnings("serial") 9 | public class IntervalWindow extends Frame{ 10 | TextField _startField; 11 | TextField _endField; 12 | TextField _lengthField; 13 | 14 | class SymFocus extends FocusAdapter{ 15 | public void focusLost(FocusEvent event){ 16 | Object object = event.getSource(); 17 | 18 | if(object == _startField){ 19 | StartField_FocusLost(event); 20 | }else if(object == _endField){ 21 | EndField_FocusLost(event); 22 | }else if(object == _lengthField){ 23 | LengthField_FocusLost(event); 24 | } 25 | } 26 | } 27 | 28 | private boolean isNotInteger(String text) { 29 | boolean result = false; 30 | try{ 31 | Integer.parseInt(text); 32 | result = true; 33 | }catch(Exception e){ 34 | 35 | } 36 | return result; 37 | } 38 | 39 | void StartField_FocusLost(FocusEvent event){ 40 | if(isNotInteger(_startField.getText())){ 41 | _startField.setText("0"); 42 | } 43 | calculateLength(); 44 | } 45 | 46 | void EndField_FocusLost(FocusEvent event){ 47 | if(isNotInteger(_endField.getText())){ 48 | _endField.setText("0"); 49 | } 50 | calculateLength(); 51 | } 52 | 53 | void LengthField_FocusLost(FocusEvent event){ 54 | if(isNotInteger(_lengthField.getText())){ 55 | _lengthField.setText("0"); 56 | } 57 | calculateEnd(); 58 | } 59 | 60 | //도메인 61 | void calculateLength(){ 62 | try{ 63 | int start = Integer.parseInt(_startField.getText()); 64 | int end = Integer.parseInt(_endField.getText()); 65 | int length = end - start; 66 | _lengthField.setText(String.valueOf(length)); 67 | }catch(NumberFormatException e){ 68 | throw new RuntimeException("잘못된 숫자 형식 에러"); 69 | } 70 | } 71 | 72 | void calculateEnd(){ 73 | try{ 74 | int start = Integer.parseInt(_startField.getText()); 75 | int length = Integer.parseInt(_endField.getText()); 76 | int end = start + length; 77 | _lengthField.setText(String.valueOf(end)); 78 | }catch(NumberFormatException e){ 79 | throw new RuntimeException("잘못된 숫자 형식 에러"); 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/com/kws/eight/six/IntervalWindowChange.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.six; 2 | 3 | import java.awt.Frame; 4 | import java.awt.TextField; 5 | import java.awt.event.FocusAdapter; 6 | import java.awt.event.FocusEvent; 7 | import java.util.Observable; 8 | import java.util.Observer; 9 | 10 | @SuppressWarnings("serial") 11 | public class IntervalWindowChange extends Frame implements Observer{ 12 | 13 | private Interval _subject; 14 | 15 | TextField _startField; 16 | TextField _endField; 17 | TextField _lengthField; 18 | 19 | public IntervalWindowChange(){ 20 | _subject = new Interval(); 21 | _subject.addObserver(this); 22 | update(_subject, null); 23 | } 24 | 25 | public String getEnd(){ 26 | return _subject.getEnd(); 27 | } 28 | 29 | public void setEnd(String arg){ 30 | _subject.setEnd(arg); 31 | } 32 | 33 | public String getStart(){ 34 | return _subject.getStart(); 35 | } 36 | 37 | public void setStart(String arg){ 38 | _subject.setStart(arg); 39 | } 40 | 41 | public String getLength(){ 42 | return _subject.getStart(); 43 | } 44 | 45 | public void setLength(String arg){ 46 | _subject.setLength(arg); 47 | } 48 | 49 | class SymFocus extends FocusAdapter{ 50 | public void focusLost(FocusEvent event){ 51 | Object object = event.getSource(); 52 | 53 | if(object == _startField){ 54 | StartField_FocusLost(event); 55 | }else if(object == _endField){ 56 | EndField_FocusLost(event); 57 | }else if(object == _lengthField){ 58 | LengthField_FocusLost(event); 59 | } 60 | } 61 | } 62 | 63 | private boolean isNotInteger(String text) { 64 | boolean result = false; 65 | try{ 66 | Integer.parseInt(text); 67 | result = true; 68 | }catch(Exception e){ 69 | 70 | } 71 | return result; 72 | } 73 | 74 | void StartField_FocusLost(FocusEvent event){ 75 | if(isNotInteger(getStart())){ 76 | setStart("0"); 77 | } 78 | _subject.calculateLength(); 79 | } 80 | 81 | void EndField_FocusLost(FocusEvent event){ 82 | setEnd(_endField.getText()); 83 | if(isNotInteger(getEnd())){ 84 | setEnd("0"); 85 | } 86 | _subject.calculateLength(); 87 | } 88 | 89 | void LengthField_FocusLost(FocusEvent event){ 90 | if(isNotInteger(getLength())){ 91 | setLength("0"); 92 | } 93 | _subject.calculateEnd(); 94 | } 95 | 96 | @Override 97 | public void update(Observable o, Object arg) { 98 | _endField.setText(_subject.getEnd()); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/com/kws/eight/sixteen/Female.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.sixteen; 2 | 3 | public class Female extends Person{ 4 | 5 | protected Female(boolean isMale, char code) { 6 | super(false, 'F'); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/com/kws/eight/sixteen/Male.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.sixteen; 2 | 3 | public class Male extends Person{ 4 | 5 | protected Male(boolean isMale, char code) { 6 | super(true, 'M'); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/com/kws/eight/sixteen/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.sixteen; 2 | 3 | class Person { 4 | private final boolean _isMale; 5 | private final char _code; 6 | 7 | static Person createMale(){ 8 | return new Person(true,'M'); 9 | } 10 | 11 | static Person createFemale(){ 12 | return new Person(false,'F'); 13 | } 14 | 15 | protected Person (boolean isMale,char code) { 16 | this._isMale = isMale; 17 | this._code = code; 18 | } 19 | 20 | public static void main(String[] args) { 21 | Person kent = Person.createMale(); 22 | } 23 | 24 | boolean isMale(){ 25 | return _isMale; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/kws/eight/ten/Name.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.ten; 2 | 3 | public class Name { 4 | private String name; 5 | 6 | public String getName() { 7 | return name; 8 | } 9 | 10 | public void setName(String name) { 11 | this.name = name; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/com/kws/eight/thirteen/BloodGroup.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.thirteen; 2 | 3 | public class BloodGroup { 4 | 5 | public static final BloodGroup O = new BloodGroup(0); 6 | public static final BloodGroup A = new BloodGroup(1); 7 | public static final BloodGroup B = new BloodGroup(2); 8 | public static final BloodGroup AB = new BloodGroup(3); 9 | private static final BloodGroup[] values = {O ,A ,B ,AB}; 10 | 11 | private final int code; 12 | 13 | private BloodGroup(int arg){ 14 | this.code = arg; 15 | } 16 | 17 | public int getCode() { 18 | return code; 19 | } 20 | 21 | public static BloodGroup code(int arg){ 22 | return values[arg]; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/kws/eight/thirteen/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.thirteen; 2 | 3 | class Person{ 4 | 5 | private BloodGroup bloodgroup; 6 | 7 | public static final int O = BloodGroup.O.getCode(); 8 | public static final int A = BloodGroup.A.getCode(); 9 | public static final int B = BloodGroup.B.getCode(); 10 | public static final int AB = BloodGroup.AB.getCode(); 11 | 12 | // private int bloodGroup; 13 | 14 | public Person(BloodGroup arg){ 15 | // this.bloodGroup = arg; 16 | this.bloodgroup = arg; 17 | } 18 | 19 | public BloodGroup getBloodGroup() { 20 | // return bloodGroup; 21 | return bloodgroup; 22 | } 23 | 24 | public void setBloodGroup(BloodGroup arg) { 25 | this.bloodgroup = arg; 26 | } 27 | 28 | public static void main(String[] args) { 29 | 30 | // Person thePerson = new Person(Person.A); 31 | Person thePerson = new Person(BloodGroup.A); 32 | 33 | thePerson.getBloodGroup().getCode(); 34 | 35 | // thePerson.setBloodGroup(Person.AB); 36 | thePerson.setBloodGroup(BloodGroup.AB); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/kws/eight/threes/Customer.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.threes; 2 | 3 | import java.util.Dictionary; 4 | import java.util.Hashtable; 5 | 6 | public class Customer { 7 | 8 | private final String name; 9 | 10 | //public -> private 11 | private Customer(String name){ 12 | this.name = name; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | @SuppressWarnings("rawtypes") 20 | private static Dictionary _instances = new Hashtable(); 21 | // add change 22 | public static Customer create(String name){ 23 | // return new Customer(name); 24 | // 미리 load된 객체반환 25 | return ((Customer) _instances.get(name)); 26 | } 27 | 28 | static void loadCustomers(){ 29 | new Customer("우리 렌터카").store(); 30 | new Customer("커피 자판기").store(); 31 | new Customer("삼천리 가스").store(); 32 | } 33 | 34 | @SuppressWarnings("unchecked") 35 | private void store(){ 36 | _instances.put(this.getName(), this); 37 | } 38 | 39 | public static Customer getNamed(String name){ 40 | return (Customer) _instances.get(name); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/kws/eight/threes/Order.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.threes; 2 | 3 | import java.util.Collection; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | import com.kws.eight.Log; 8 | 9 | public class Order { 10 | 11 | private Customer customer; 12 | 13 | public Order(String customerName){ 14 | this.customer = Customer.create(customerName); 15 | } 16 | 17 | public String getCustomer() { 18 | return customer.getName(); 19 | } 20 | 21 | // public void setCustomer(String customerName) { 22 | // this.customer = new Customer(customerName); 23 | // } 24 | 25 | @SuppressWarnings({ "unused", "rawtypes" }) 26 | private static int numberOrderFor(Collection orders, String customer){ 27 | 28 | int result = 0; 29 | 30 | Iterator iter = orders.iterator(); 31 | 32 | while(iter.hasNext()){ 33 | Order each = (Order) iter.next(); 34 | if(each.getCustomer().equals(customer)){ 35 | result++; 36 | } 37 | } 38 | 39 | return result; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/kws/eight/twos/Customer.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.twos; 2 | 3 | public class Customer { 4 | private final String name; 5 | 6 | public Customer(String customer) { 7 | this.name = customer; 8 | } 9 | 10 | public String getCustomers() { 11 | return this.name; 12 | } 13 | // 14 | } 15 | -------------------------------------------------------------------------------- /src/com/kws/eight/twos/OrderAfter.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.twos; 2 | 3 | import java.util.Collection; 4 | import java.util.Iterator; 5 | 6 | 7 | public class OrderAfter { 8 | 9 | private Customer _customer; 10 | 11 | public OrderAfter(String arg) { 12 | this._customer = new Customer(arg); 13 | } 14 | 15 | public String getCustomers(){ 16 | return _customer.getCustomers(); 17 | } 18 | 19 | public void setCustomer(String customer){ 20 | _customer = new Customer(customer); 21 | } 22 | 23 | @SuppressWarnings("rawtypes") 24 | private static int numberOrderFor(Collection orders, String customer){ 25 | 26 | int result = 0; 27 | 28 | Iterator iter = orders.iterator(); 29 | 30 | while(iter.hasNext()){ 31 | OrderAfter each = (OrderAfter) iter.next(); 32 | if(each.getCustomers().equals(customer)){ 33 | result++; 34 | } 35 | } 36 | 37 | return result; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/kws/eight/twos/OrderBefore.java: -------------------------------------------------------------------------------- 1 | package com.kws.eight.twos; 2 | 3 | import java.util.Collection; 4 | import java.util.Iterator; 5 | 6 | public class OrderBefore { 7 | private String customer; 8 | 9 | 10 | public String getCustomer() { 11 | return customer; 12 | } 13 | 14 | public void setCustomer(String customer) { 15 | this.customer = customer; 16 | } 17 | 18 | private static int numberOrderFor(Collection orders, String customer){ 19 | int result = 0; 20 | Iterator iter = orders.iterator(); 21 | while(iter.hasNext()){ 22 | OrderBefore each = (OrderBefore) iter.next(); 23 | if(each.getCustomer().equals(customer)){ 24 | result++; 25 | } 26 | } 27 | return result; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/com/kws/four/FileReaderTest4Unit.java: -------------------------------------------------------------------------------- 1 | package com.kws.four; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import java.io.FileNotFoundException; 8 | import java.io.FileReader; 9 | import java.io.IOException; 10 | 11 | import static junit.framework.TestCase.assertEquals; 12 | 13 | /** 14 | * Created by jihoon on 2016. 5. 15.. 15 | */ 16 | public class FileReaderTest4Unit { 17 | 18 | 19 | private FileReader _input; 20 | 21 | @Before 22 | public void setUp() { 23 | try { 24 | _input = new FileReader("/Users/jihoon/workspaceStudy/Refactoring/Refactoring/src/com/kws/testFixture/data.txt"); 25 | } catch(FileNotFoundException e) { 26 | throw new RuntimeException("파일을 열 수 없습니다"); 27 | } 28 | } 29 | 30 | 31 | @After 32 | public void tearDown() { 33 | try { 34 | _input.close(); 35 | 36 | } catch(IOException e) { 37 | throw new RuntimeException("파일을 닫는 중 에러 발생"); 38 | } 39 | } 40 | 41 | @Test 42 | public void read() throws IOException { 43 | char ch = '&'; 44 | // _input.close(); 45 | for (int i=0; i<4; i++) { 46 | ch = (char) _input.read(); 47 | System.out.println(ch); 48 | } 49 | // assertTrue('d'==ch); 50 | 51 | assert('m' == ch); 52 | assertEquals('d', ch); 53 | } 54 | 55 | public int test(int i){ 56 | return 0; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/com/kws/four/FileReaderTester.java: -------------------------------------------------------------------------------- 1 | package com.kws.four; 2 | 3 | 4 | import java.io.File; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.FileReader; 8 | import java.io.IOException; 9 | 10 | import junit.framework.Test; 11 | import junit.framework.TestCase; 12 | import junit.framework.TestSuite; 13 | 14 | /** 15 | * Created by jihoon on 2016. 5. 15.. 16 | */ 17 | public class FileReaderTester extends TestCase { 18 | 19 | private FileReader _input; 20 | private FileReader _empty; 21 | 22 | public FileReaderTester(String name) { 23 | super(name); 24 | } 25 | 26 | protected void setUp() { 27 | try { 28 | _input = new FileReader("/Users/jihoon/workspaceStudy/Refactoring/Refactoring/src/com/kws/testFixture/data.txt"); 29 | _empty = newEmptyFile(); 30 | } catch(FileNotFoundException e) { 31 | throw new RuntimeException("테스트 파일을 열 수 없음"); 32 | } catch(IOException ioe) { 33 | throw new RuntimeException(ioe.toString()); 34 | } 35 | } 36 | 37 | private FileReader newEmptyFile() throws IOException { 38 | File empty = new File("/Users/jihoon/workspaceStudy/Refactoring/Refactoring/src/com/kws/testFixture/empty.txt"); 39 | FileOutputStream out = new FileOutputStream(empty); 40 | out.close(); 41 | return new FileReader(empty); 42 | } 43 | 44 | protected void tearDown() { 45 | try { 46 | _input.close(); 47 | 48 | } catch(IOException e) { 49 | throw new RuntimeException("테스트파일을 닫는 중 에러 발생"); 50 | } 51 | } 52 | 53 | public void testRead() throws IOException { 54 | char ch = '&'; 55 | // _input.close(); 56 | for (int i=0; i<4; i++) { 57 | ch = (char) _input.read(); 58 | System.out.println("!!!!!!"+ ch); 59 | } 60 | // assertTrue('d'==ch); 61 | // assert('2' == ch); 62 | assertEquals('d', ch); 63 | } 64 | 65 | public static Test suite() { 66 | TestSuite suite = new TestSuite(); 67 | suite.addTest(new FileReaderTester("testRead"));//메서드 name 을 넘기면 실행 68 | suite.addTest(new FileReaderTester("testReadAtEnd"));//메서드 name 을 넘기면 실행 69 | suite.addTest(new FileReaderTester("testReadBoundaries"));//메서드 name 을 넘기면 실행 70 | suite.addTest(new FileReaderTester("testEmptyRead"));//메서드 name 을 넘기면 실행 71 | suite.addTest(new FileReaderTester("testReadAfterClose"));//메서드 name 을 넘기면 실행 72 | return suite; 73 | } 74 | 75 | public void testReadAtEnd() throws IOException { 76 | int ch = -1234; 77 | for (int i=0; i<141; i++) { 78 | ch = _input.read(); 79 | } 80 | 81 | assertEquals("read at end", -1, ch); 82 | } 83 | 84 | public void testReadBoundaries() throws IOException { 85 | assertEquals("read first char", 'B', (char) _input.read()); 86 | int ch = 0; 87 | for (int i=0; i<140; i++) { 88 | ch = _input.read(); 89 | 90 | } 91 | System.out.println(ch); 92 | // assertEquals("read last char", '6', ch); 93 | assertEquals("read at end", -1, _input.read()); 94 | // assertEquals("read at end", -1, _input.read()); 95 | } 96 | 97 | public void testEmptyRead() throws IOException { 98 | assertEquals(-1, _empty.read()); 99 | } 100 | 101 | public void testReadAfterClose() throws IOException { 102 | _input.close(); 103 | try { 104 | _input.read(); 105 | fail("no exception for read past end"); 106 | 107 | } catch(IOException e) { } 108 | } 109 | 110 | 111 | } -------------------------------------------------------------------------------- /src/com/kws/nine/ConsolidateConditional.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | /** 4 | * Created by jihoon on 2016. 6. 6.. 5 | * 중복조건식 통합 6 | */ 7 | public class ConsolidateConditional { 8 | 9 | 10 | public static final double IS_PART_TIME = 0; 11 | public static final double MONTHS_DISABLED = 0; 12 | public static final double SENIORITY = 0; 13 | 14 | public double disabilityAmount(){ 15 | double returnValue = 0; 16 | if (SENIORITY < 2) return returnValue; 17 | if (MONTHS_DISABLED < 2) return returnValue; 18 | if (IS_PART_TIME < 2) return returnValue; 19 | return returnValue; 20 | } 21 | 22 | 23 | public double afterDisabilityAmount(){ 24 | double returnValue = 0 ; 25 | if(SENIORITY < 2 || MONTHS_DISABLED < 2 || IS_PART_TIME < 2){ 26 | return returnValue; 27 | } 28 | return returnValue; 29 | } 30 | 31 | public double ExtractMethodDisabilityAmount(){ 32 | double returnValue = 0 ; 33 | if(isNotEligibleForDisability()){ 34 | return returnValue; 35 | } 36 | return returnValue; 37 | } 38 | 39 | private boolean isNotEligibleForDisability() { 40 | return SENIORITY < 2 || MONTHS_DISABLED < 2 || IS_PART_TIME < 2; 41 | } 42 | 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/kws/nine/ConsolidateDuplicate.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | /** 4 | * Created by jihoon on 2016. 6. 6.. 5 | */ 6 | public class ConsolidateDuplicate { 7 | 8 | public static void main(String[] args) { 9 | int total = 0; 10 | int price = 0; 11 | 12 | if(isSpecialDeal()){ 13 | total = price * 9; 14 | send(); 15 | }else { 16 | total = price * 9; 17 | send(); 18 | } 19 | 20 | } 21 | 22 | public static boolean isSpecialDeal(){ 23 | return false; 24 | } 25 | 26 | public static int send(){ 27 | return 5; 28 | } 29 | 30 | } 31 | 32 | 33 | 34 | class afterConsolidateDuplicate{ 35 | 36 | public static void main(String[] args) { 37 | 38 | 39 | int total = 0; 40 | int price = 0; 41 | 42 | if(isSpecialDeal()){ 43 | total = price * 9; 44 | }else { 45 | total = price * 9; 46 | } 47 | send(); 48 | } 49 | public static boolean isSpecialDeal(){ 50 | return false; 51 | } 52 | 53 | public static int send(){ 54 | return 3; 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /src/com/kws/nine/DecomposeConditional.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | import java.text.DateFormat; 4 | import java.text.ParseException; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Date; 7 | 8 | /** 9 | * Created by jihoon on 2016. 6. 6.. 10 | */ 11 | public class DecomposeConditional { 12 | public static int CHARGE = 0; 13 | public static final int QUANTITY = 100; 14 | public static final int WINTER_RATE = 300; 15 | public static final int SUMMER_RATE = 200; 16 | public static final int WINTER_SERVICE_CHARGE = 50; 17 | 18 | public static void main(String[] args) throws ParseException { 19 | Date date = new Date(); 20 | 21 | String summerStart = "20160501"; 22 | String summerEnd = "20160930"; 23 | 24 | DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); 25 | Date SUMMER_START = dateFormat.parse(summerStart); // Date로 변환 26 | Date SUMMER_END = dateFormat.parse(summerEnd); // Date로 변환 27 | System.out.println(SUMMER_START); 28 | System.out.println(SUMMER_END); 29 | 30 | 31 | //겨울인지 여름인지 따라 달라지는 난방비를 계산하는 코드 32 | //여름 시작일이랑 여름 종료일을 정해주자 33 | //여름 시작전 이거나 여름이 끝난후 즉 겨울 34 | if (date.before(SUMMER_START) || date.after(SUMMER_END)) { 35 | System.out.println("겨울겨울겨울"); 36 | CHARGE = QUANTITY * WINTER_RATE + WINTER_SERVICE_CHARGE; 37 | }//지금은 여름 38 | else { 39 | System.out.println("여름여름여름"); 40 | CHARGE = QUANTITY * SUMMER_RATE; 41 | } 42 | System.out.println("CHARGE ==== " + CHARGE); 43 | } 44 | 45 | } 46 | 47 | 48 | 49 | class aftersource{ 50 | public static int CHARGE = 0; 51 | public static final int QUANTITY = 100; 52 | public static final int WINTER_RATE = 300; 53 | public static final int SUMMER_RATE = 200; 54 | public static final int WINTER_SERVICE_CHARGE = 50; 55 | 56 | public static void main(String[] args) throws ParseException { 57 | //리팩토링을 해보자~ 58 | Date date = new Date(); 59 | 60 | String summerStart = "20160501"; 61 | String summerEnd = "20160930"; 62 | 63 | DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); 64 | Date SUMMER_START = dateFormat.parse(summerStart); // Date로 변환 65 | Date SUMMER_END = dateFormat.parse(summerEnd); // Date로 변환 66 | System.out.println(SUMMER_START); 67 | System.out.println(SUMMER_END); 68 | 69 | //1. 조건식 if절 과 각 분기 절을 다음과 같이 각각의 메서드로 빼자 70 | if (notSummer(date, SUMMER_START, SUMMER_END)) { 71 | System.out.println("겨울겨울겨울"); 72 | CHARGE = winterCharge(); 73 | }//지금은 여름 74 | else { 75 | System.out.println("여름여름여름"); 76 | CHARGE = summerCharge(); 77 | } 78 | System.out.println("CHARGE ==== " + CHARGE); 79 | } 80 | 81 | private static int summerCharge() { 82 | return QUANTITY * SUMMER_RATE; 83 | } 84 | 85 | private static int winterCharge() { 86 | return QUANTITY * WINTER_RATE + WINTER_SERVICE_CHARGE; 87 | } 88 | 89 | private static boolean notSummer(Date date, Date SUMMER_START, Date SUMMER_END) { 90 | return date.before(SUMMER_START) || date.after(SUMMER_END); 91 | } 92 | } 93 | 94 | 95 | -------------------------------------------------------------------------------- /src/com/kws/nine/IntroduceAssertion.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | /** 4 | * Created by jihoon on 2016. 6. 11.. 5 | * 어선셜 넣기 6 | */ 7 | public class IntroduceAssertion { 8 | /* double getExpenseLimit(){ 9 | //비용 한도를 두든지 주요 프로젝트를 정해야 한다 10 | return(_expenseLimit != NULL_EXPENSE) ? _expenseLimit: _primaryProject.getMemberExpenseLimit(); 11 | } 12 | 13 | 14 | double getExpenseLimit(){ 15 | Assert.isTrue(_expenseLimit != NULL_EXPENSE || _primaryProject != null); 16 | return (_expenseLimit != NULL_EXPENSE) ? _expenseLimit:_primaryProject.getMemberExpenseLimit(); 17 | }*/ 18 | } 19 | -------------------------------------------------------------------------------- /src/com/kws/nine/IntroduceNullObject.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | /** 4 | * Created by jihoon on 2016. 6. 11.. 5 | * null 검사를 널객체에 위임 6 | */ 7 | public class IntroduceNullObject { 8 | /* 9 | if(customer == null) { 10 | plan = BillingPlan.basic(); 11 | }else { 12 | plan = customer.getPlan(); 13 | } 14 | */ 15 | 16 | //예제 17 | class site { 18 | Customer _customer; 19 | 20 | Customer getCustomer() { 21 | return _customer; 22 | } 23 | } 24 | 25 | class Customer { 26 | String name; 27 | String plan; 28 | String history; 29 | 30 | public String getName() { 31 | return this.getName(); 32 | } 33 | 34 | public String getPlan() { 35 | return this.getPlan(); 36 | } 37 | 38 | public String getHistory() { 39 | return getHistory(); 40 | } 41 | } 42 | 43 | 44 | class PayMentHistory { 45 | int getWeekDelinquentInLastYear() { 46 | return 0; 47 | }; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/kws/nine/RemoveControlFlag.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | /** 4 | * Created by jihoon on 2016. 6. 6.. 5 | * 제어 플래그 제거 6 | */ 7 | public class RemoveControlFlag { 8 | 9 | // 1. 간단한 제어플래그를 break문으로 교체 10 | //여러 사람중에 하드코딩한 용의자 don과 john이있는지 검사 11 | public void checkSecurityBefore(String[] people) { 12 | boolean found = false; 13 | for (int i = 0; i < people.length; i++) { 14 | if (!found) { 15 | if (people[i].equals("Don")) { 16 | sendAlert(); 17 | found = true;//이부분이 제어플래그 18 | } 19 | if (people[i].equals("John")) { 20 | sendAlert(); 21 | found = true;//이부분이 제어플래그 22 | } 23 | } 24 | } 25 | } 26 | 27 | //위에서 제어플래그 위치를 찾고 28 | //제어플래그를 break로 바꾸고 29 | //이전에 제어플래그로 참조하던곳을 전부 삭제 30 | public void checkSecurityAfter(String[] people) { 31 | 32 | for (int i = 0; i < people.length; i++) { 33 | if (people[i].equals("Don")) { 34 | sendAlert(); 35 | break;//이부분이 제어플래그 36 | } 37 | if (people[i].equals("John")) { 38 | sendAlert(); 39 | break;//이부분이 제어플래그 40 | } 41 | } 42 | } 43 | 44 | /* 45 | 46 | public void checkSecurityBefore2(String people) { 47 | String found = ""; 48 | for (int i = 0; i < people.length(); i++) { 49 | if (found.equals("")) { 50 | if (people[i].equals("Don")) { 51 | sendAlert(); 52 | found = "Don"; 53 | } 54 | if (people[i].equals("John")) { 55 | sendAlert(); 56 | found = "John"; 57 | } 58 | } 59 | } 60 | someLaterCode(found); 61 | } 62 | 63 | */ 64 | 65 | 66 | // 2. 제어 플래그를 return 문으로 교체 67 | // 여기서 found 변수는 두가지 역할을 한다 68 | // 1. 결과를 나타내고 제어플래그 역할을 한다 69 | // 2. 이럴때는 found변수를 알아내는 코드를 메서드로 빼내자 70 | public void checkSecurityBefore2(String[] people) { 71 | String found = foundMiscreant(people); 72 | someLaterCode(found); 73 | } 74 | 75 | private String foundMiscreant(String[] people) { 76 | 77 | for (int i = 0; i < people.length; i++) { 78 | if (people[i].equals("Don")) { 79 | sendAlert(); 80 | //found = "Don"; 제어플래그를 return문으로 교체 81 | return "Don"; 82 | } 83 | if (people[i].equals("John")) { 84 | sendAlert(); 85 | //found = "John"; 86 | return "John"; 87 | } 88 | } 89 | return ""; 90 | } 91 | 92 | 93 | public void sendAlert() { 94 | 95 | } 96 | 97 | public void someLaterCode(String found) { 98 | 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/com/kws/nine/ReplaceConditional.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | /** 4 | * Created by jihoon on 2016. 6. 11.. 5 | * 조건문을 재정의로 전환 6 | */ 7 | public class ReplaceConditional { 8 | public static final String EUROPEAN ="유럽"; 9 | public static final String AFRICAN ="아프리카"; 10 | public static final String NORWEGIAN_BLUE ="노르웨이"; 11 | 12 | // double getSpeed(String _type){ 13 | // switch (_type){ 14 | // case EUROPEAN: 15 | // return getBaseSpeed(); 16 | // case AFRICAN: 17 | // return getBaseSpeed() - getLoadFactor() * _numberOfCoconuts; 18 | // case NORWEGIAN_BLUE: 19 | // return (_isNailed) ? 0 : getBaseSpeed(_voltage); 20 | // } 21 | // throw new RuntimeException("불가능한 속도"); 22 | // } 23 | // 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/com/kws/nine/ReplaceNestedConditional.java: -------------------------------------------------------------------------------- 1 | package com.kws.nine; 2 | 3 | /** 4 | * Created by jihoon on 2016. 6. 11.. 5 | * 여러겹의 조건문을 감시 절로 전환 6 | */ 7 | public class ReplaceNestedConditional { 8 | /* 9 | double getPayAmount() { 10 | boolean _isDead = false; 11 | boolean _isSeparated = false; 12 | boolean _isRetired = false; 13 | double result; 14 | if (_isDead) { 15 | result = deadAmount(); 16 | } else { 17 | if (_isSeparated) { 18 | result = seperatedAmount(); 19 | } else { 20 | if (_isRetired) { 21 | result = retiredAmount(); 22 | } else { 23 | result = normalPayAmount(); 24 | } 25 | } 26 | } 27 | return result; 28 | } 29 | 30 | double getPayAmount() { 31 | boolean _isDead = false; 32 | boolean _isSeparated = false; 33 | boolean _isRetired = false; 34 | if (_isDead) return deadAmount(); 35 | if (_isSeparated) return separatedAmount(); 36 | if (_isRetired) return retiredAmount(); 37 | return normalPayAmount(); 38 | } 39 | 40 | 41 | double deadAmount() { 42 | } 43 | 44 | ; 45 | 46 | double seperatedAmount() { 47 | } 48 | 49 | ; 50 | 51 | double retiredAmount() { 52 | } 53 | 54 | ; 55 | 56 | double separatedAmount() { 57 | } 58 | 59 | ; 60 | 61 | 62 | */ 63 | } 64 | -------------------------------------------------------------------------------- /src/com/kws/one/after/Customer.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.after; 2 | 3 | import java.util.Enumeration; 4 | import java.util.Iterator; 5 | import java.util.Vector; 6 | 7 | public class Customer { 8 | private String _name; 9 | private Vector _rentals = new Vector(); 10 | 11 | public Customer(String name) { 12 | _name = name; 13 | } 14 | 15 | public void addRental(Rental arg) { 16 | _rentals.addElement(arg); 17 | } 18 | 19 | public String getName() { 20 | return _name; 21 | } 22 | 23 | //리팩토링이 필요한 핵심 메서드 24 | //너무 많은 기능을 가지고 있다 25 | public String statement() { 26 | int frequentRenterPoints = 0; 27 | Iterator rentals = _rentals.iterator(); 28 | String result = getName() + " 고객님의 대여 기록 \n"; 29 | 30 | while(rentals.hasNext()) { 31 | Rental each = (Rental) rentals.next(); 32 | 33 | //대여하는 비디오 정보와 대여로를 출 34 | result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "\n"; 35 | } 36 | 37 | //footer 38 | result += "누적 대여료 : " + String.valueOf(getTotalCharge()) + "\n"; 39 | result += "적립 포인트 : " + String.valueOf(getTotalFrequentRenterPoints()); 40 | return result; 41 | } 42 | 43 | public String htmlStatement() { 44 | Iterator rentals = _rentals.iterator(); 45 | String result = "

" + getName() + "고객님의 대여 기록

\n"; 46 | while(rentals.hasNext()) { 47 | Rental each = (Rental) rentals.next(); 48 | 49 | //모든 대여 비디오 정보와 대여로를 출 50 | result += each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "
\n"; 51 | } 52 | //footer 53 | result += "

누적 대여료 : " + String.valueOf(getTotalCharge()) + "

\n"; 54 | result += "

적립 포인트 : " + String.valueOf(getTotalFrequentRenterPoints()) + " rentals = _rentals.iterator(); 62 | 63 | while (rentals.hasNext()) { 64 | Rental each = (Rental) rentals.next(); 65 | result += each.getCharge(); 66 | } 67 | return result; 68 | } 69 | 70 | private int getTotalFrequentRenterPoints() { 71 | int result = 0; 72 | 73 | Iterator rentals = _rentals.iterator(); 74 | 75 | while (rentals.hasNext()) { 76 | Rental each = (Rental) rentals.next(); 77 | result += each.getFrequentRenterPoints(); 78 | } 79 | return result; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/com/kws/one/after/ExamTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.after; 2 | 3 | public class ExamTest { 4 | public static void main(String [] args) { 5 | 6 | Customer customer = new Customer("돈일"); 7 | 8 | Movie movie1 = new Movie("시빌워", Movie.NEW_RELEASE); 9 | Movie movie2 = new Movie("탐정 홍길동",Movie.CHILDRENS); 10 | 11 | Rental rental = new Rental(movie1, 3); 12 | Rental rental2 = new Rental(movie2, 4); 13 | 14 | customer.addRental(rental); 15 | customer.addRental(rental2); 16 | 17 | System.out.println(customer.statement()); 18 | System.out.println(customer.htmlStatement()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/kws/one/after/Movie.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.after; 2 | 3 | public class Movie { 4 | public static final int CHILDRENS = 2; 5 | public static final int REGULAR = 0; 6 | public static final int NEW_RELEASE = 1; 7 | private String _title; 8 | private Price _price; 9 | 10 | public Movie(String title, int priceCode){ 11 | _title = title; 12 | setPriceCode(priceCode); 13 | } 14 | 15 | public int getPriceCode() { 16 | return _price.getPriceCode(); 17 | } 18 | 19 | public void setPriceCode(int arg) { 20 | switch(arg) { 21 | case REGULAR: 22 | _price = new RegularPrice(); 23 | break; 24 | case CHILDRENS: 25 | _price = new ChildrensPrice(); 26 | break; 27 | case NEW_RELEASE: 28 | _price = new NewReleasePrice(); 29 | break; 30 | } 31 | } 32 | 33 | public String getTitle() { 34 | return _title; 35 | } 36 | 37 | //별도의 메서드로 작성 38 | public double getCharge(int daysRented) { 39 | return _price.getCharge(daysRented); 40 | } 41 | 42 | public int getFrequentRenterPoints(int daysRented) { 43 | 44 | if((getPriceCode() == Movie.NEW_RELEASE) && daysRented > 1) 45 | return 2; 46 | else { 47 | return 1; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/kws/one/after/Price.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.after; 2 | 3 | public abstract class Price { 4 | abstract int getPriceCode(); 5 | abstract double getCharge(int daysRented); 6 | 7 | public int getFrequentRenterPoints(int daysRented) { 8 | return 1; 9 | } 10 | } 11 | 12 | 13 | class ChildrensPrice extends Price { 14 | 15 | @Override 16 | double getCharge(int daysRented) { 17 | double result = 1.5; 18 | if(daysRented > 3) 19 | result += (daysRented - 3) * 1.5; 20 | return result; 21 | } 22 | 23 | @Override 24 | int getPriceCode() { 25 | return Movie.CHILDRENS; 26 | } 27 | 28 | } 29 | 30 | class NewReleasePrice extends Price { 31 | 32 | @Override 33 | public int getFrequentRenterPoints(int daysRented){ 34 | return (daysRented >1) ? 2:1; 35 | } 36 | 37 | @Override 38 | double getCharge(int daysRented) { 39 | return daysRented *3; 40 | } 41 | 42 | @Override 43 | int getPriceCode() { 44 | return Movie.NEW_RELEASE; 45 | } 46 | 47 | } 48 | 49 | class RegularPrice extends Price { 50 | 51 | @Override 52 | double getCharge(int daysRented) { 53 | double result = 2; 54 | if(daysRented > 2) 55 | result += (daysRented - 2) * 1.5; 56 | return result; 57 | } 58 | 59 | @Override 60 | int getPriceCode() { 61 | return Movie.REGULAR; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/kws/one/after/Rental.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.after; 2 | 3 | public class Rental { 4 | private Movie _movie; 5 | private int _daysRented; 6 | 7 | public Rental(Movie movie, int daysRented) { 8 | _movie = movie; 9 | _daysRented = daysRented; 10 | } 11 | 12 | public int getDaysRented() { 13 | return _daysRented; 14 | } 15 | 16 | public Movie getMovie() { 17 | return _movie; 18 | } 19 | 20 | //별도의 메서드로 작성 21 | public double getCharge() { 22 | return _movie.getCharge(_daysRented); 23 | } 24 | 25 | public int getFrequentRenterPoints() { 26 | return _movie.getFrequentRenterPoints(_daysRented); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/kws/one/before/Customer.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.before; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Enumeration; 6 | import java.util.Vector; 7 | 8 | public class Customer { 9 | private String _name; 10 | private Vector _rentals = new Vector(); 11 | 12 | public Customer(String name) { 13 | _name = name; 14 | } 15 | 16 | public void addRental(Rental arg) { 17 | _rentals.addElement(arg); 18 | } 19 | 20 | public String getName() { 21 | return _name; 22 | } 23 | 24 | //리팩토링이 필요한 핵심 메서드 25 | //너무 많은 기능을 가지고 있다 26 | public String statement() { 27 | double totalAmount = 0; 28 | int frequentRenterPoints = 0; 29 | Enumeration rentals = _rentals.elements(); 30 | String result = getName() + " 고객님의 대여 기록 \n"; 31 | 32 | while(rentals.hasMoreElements()) { 33 | double thisAmount = 0; 34 | Rental each = (Rental) rentals.nextElement(); 35 | 36 | //비디오 종류별 대여로 계산 37 | thisAmount = each.amountFor(); 38 | 39 | //적립 포인트 1포인트 증 40 | frequentRenterPoints ++; 41 | 42 | //최신물을 이틀 이상 대여하면 보너스 포인트 지급 43 | if((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) && each.getDaysRented() > 1) 44 | frequentRenterPoints++; 45 | 46 | //대여하는 비디오 정보와 대여로를 출 47 | result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n"; 48 | 49 | //현재까지 누적된 총 대여료 50 | totalAmount += thisAmount; 51 | } 52 | 53 | //footer 54 | result += "누적 대여료 : " + String.valueOf(totalAmount) + "\n"; 55 | result += "적립 포인트 : " + String.valueOf(frequentRenterPoints); 56 | return result; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/com/kws/one/before/ExamTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.before; 2 | 3 | public class ExamTest { 4 | public static void main(String [] args) { 5 | 6 | Customer customer = new Customer("돈일"); 7 | 8 | Movie movie1 = new Movie("시빌워", Movie.NEW_RELEASE); 9 | Movie movie2 = new Movie("탐정 홍길동",Movie.CHILDRENS); 10 | 11 | Rental rental = new Rental(movie1, 3); 12 | Rental rental2 = new Rental(movie2, 4); 13 | 14 | customer.addRental(rental); 15 | customer.addRental(rental2); 16 | 17 | System.out.println(customer.statement()); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/kws/one/before/Movie.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.before; 2 | 3 | public class Movie { 4 | public static final int CHILDRENS = 2; 5 | public static final int REGULAR = 0; 6 | public static final int NEW_RELEASE = 1; 7 | private String _title; 8 | private int _priceCode; 9 | 10 | public Movie(String title, int priceCode){ 11 | _title = title; 12 | _priceCode = priceCode; 13 | } 14 | 15 | public int getPriceCode() { 16 | return _priceCode; 17 | } 18 | 19 | public void setPriceCode(int arg) { 20 | _priceCode = arg; 21 | } 22 | 23 | public String getTitle() { 24 | return _title; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/kws/one/before/Rental.java: -------------------------------------------------------------------------------- 1 | package com.kws.one.before; 2 | 3 | public class Rental { 4 | private Movie _movie; 5 | private int _daysRented; 6 | 7 | public Rental(Movie movie, int daysRented) { 8 | _movie = movie; 9 | _daysRented = daysRented; 10 | } 11 | 12 | public int getDaysRented() { 13 | return _daysRented; 14 | } 15 | 16 | public Movie getMovie() { 17 | return _movie; 18 | } 19 | 20 | public double amountFor() { 21 | double thisAmount = 0; 22 | switch (getMovie().getPriceCode()) { 23 | case Movie.REGULAR: 24 | thisAmount += 2; 25 | if(getDaysRented() > 2) 26 | thisAmount += (getDaysRented() - 2) * 1.5; 27 | break; 28 | case Movie.NEW_RELEASE: 29 | thisAmount += getDaysRented() * 3; 30 | break; 31 | case Movie.CHILDRENS: 32 | thisAmount += 1.5; 33 | if(getDaysRented() > 3) 34 | thisAmount += (getDaysRented() - 3) * 1.5; 35 | break; 36 | } 37 | return thisAmount; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/extractClass/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.extractClass; 2 | 3 | public class Person { 4 | private String _name; 5 | private TelephoneNumber _officeTelephone = new TelephoneNumber(); 6 | 7 | public Person(String name, String officeAreaCode, String officeNumber) { 8 | _name = name; 9 | _officeTelephone.setAreaCode(officeAreaCode); 10 | _officeTelephone.setNumber(officeNumber); 11 | } 12 | 13 | public String getName() { 14 | return _name; 15 | } 16 | 17 | public String getTelephoneNumber() { 18 | return _officeTelephone.getTelephoneNumber(); 19 | } 20 | 21 | TelephoneNumber getOfficeTelephone() { 22 | return _officeTelephone; 23 | } 24 | 25 | class TelephoneNumber { 26 | private String _areaCode; 27 | private String _number; 28 | 29 | public String getTelephoneNumber() { 30 | return ("(" + _areaCode + ")" + _number); 31 | } 32 | 33 | String getAreaCode() { 34 | return _areaCode; 35 | } 36 | 37 | void setAreaCode(String areaCode) { 38 | _areaCode = areaCode; 39 | } 40 | 41 | String getNumber() { 42 | return _number; 43 | } 44 | 45 | void setNumber(String number) { 46 | _number = number; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/hideDelegate/Department.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.hideDelegate; 2 | 3 | class Department { 4 | private String _chargeCode; 5 | private Person _manager; 6 | 7 | public Department(Person manager) { 8 | _manager = manager; 9 | } 10 | 11 | public Person getManager() { 12 | return _manager; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/hideDelegate/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.hideDelegate; 2 | 3 | public class Person { 4 | String _name; 5 | Department _department; 6 | 7 | public Person(String name) { 8 | _name = name; 9 | _department = null; 10 | } 11 | 12 | public Person(String name, Person manager) { 13 | _name = name; 14 | _department = new Department(manager); 15 | } 16 | 17 | public String getName() { 18 | return _name; 19 | } 20 | 21 | public Person getManager() { 22 | return _department.getManager(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/inlineClass/Client.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.inlineClass; 2 | 3 | public class Client { 4 | public static void main() { 5 | Person martin = new Person(); 6 | martin.setAreaCode("781"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/inlineClass/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.inlineClass; 2 | 3 | public class Person { 4 | private String _name; 5 | private TelephoneNumberOld _officeTelephone = new TelephoneNumberOld(); 6 | 7 | public String getName() { 8 | return _name; 9 | } 10 | 11 | public String getTelephoneNumber() { 12 | return _officeTelephone.getTelephoneNumber(); 13 | } 14 | 15 | // TelephoneNumberOld getOfficeTelephone() { 16 | // return _officeTelephone; 17 | // } 18 | 19 | String getAreaCode() { 20 | return _officeTelephone.getAreaCode(); 21 | } 22 | 23 | void setAreaCode(String arg) { 24 | _officeTelephone.setAreaCode(arg); 25 | } 26 | 27 | String getNumber() { 28 | return _officeTelephone.getNumber(); 29 | } 30 | 31 | void setNumber(String arg) { 32 | _officeTelephone.setNumber(arg); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/inlineClass/TelephoneNumber.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.inlineClass; 2 | 3 | class TelephoneNumberOld { 4 | 5 | private String _areaCode; 6 | private String _number; 7 | 8 | public String getTelephoneNumber() { 9 | return ("(" + _areaCode + ")" + _number); 10 | } 11 | 12 | String getAreaCode() { 13 | return _areaCode; 14 | } 15 | 16 | void setAreaCode(String arg) { 17 | _areaCode = arg; 18 | } 19 | 20 | String getNumber() { 21 | return _number; 22 | } 23 | 24 | void setNumber(String arg) { 25 | _number = arg; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/introduceForeignMethod/StartDate.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.introduceForeignMethod; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | 6 | public class StartDate { 7 | public Calendar getNextStartDateByCalendar(Calendar previousEnd) { 8 | return getNextDay(previousEnd); 9 | } 10 | 11 | public Date getNextStartDateByDate(Date previousEnd) { 12 | return getNextDay(previousEnd); 13 | } 14 | 15 | private static Calendar getNextDay(Calendar arg) { 16 | Calendar newStart = (Calendar)arg.clone(); 17 | newStart.add(Calendar.DAY_OF_MONTH, 1); 18 | return newStart; 19 | } 20 | 21 | private static Date getNextDay(Date arg) { 22 | Date newStart = new Date(arg.getYear(), arg.getMonth(), arg.getDate() + 1); 23 | return newStart; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/moveField/Account.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.moveField; 2 | 3 | public class Account { 4 | private AccountType _type; 5 | 6 | public Account(String owner) { 7 | _type = new AccountType(owner); 8 | 9 | if (owner.equals("홍길동")) { 10 | setInterestRate(0.3); 11 | } else { 12 | setInterestRate(4.5); 13 | } 14 | } 15 | 16 | public double interestForAmount_days(double amount, int days) { 17 | return getInterestRate() * amount * days / 365; 18 | } 19 | 20 | private void setInterestRate(double arg) { 21 | _type.setInterestRate(arg); 22 | } 23 | 24 | private double getInterestRate() { 25 | return _type.getInterestRate(); 26 | } 27 | } -------------------------------------------------------------------------------- /src/com/kws/seven/after/moveField/AccountType.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.moveField; 2 | 3 | public class AccountType { 4 | private String _owner; 5 | private double _interestRate; 6 | 7 | public AccountType(String owner) { 8 | _owner = owner; 9 | } 10 | 11 | public double getInterestRate() { 12 | return _interestRate; 13 | } 14 | 15 | public void setInterestRate(double interestRate) { 16 | _interestRate = interestRate; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/moveMethod/Account.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.moveMethod; 2 | 3 | public class Account { 4 | private AccountType _type; 5 | private int _daysOverdrawn; 6 | 7 | public Account(String owner) { 8 | _type = new AccountType(owner); 9 | } 10 | 11 | double overdraftCharge() { 12 | return _type.overdraftCharge(_daysOverdrawn); 13 | } 14 | 15 | double bankCharge() { 16 | double result = 4.5; 17 | if (_daysOverdrawn > 0) { 18 | result += _type.overdraftCharge(_daysOverdrawn); 19 | } 20 | return result; 21 | } 22 | 23 | public void setDayOverdrawn(int dayOverdrawn) { 24 | _daysOverdrawn = dayOverdrawn; 25 | } 26 | 27 | public int getDayOverdrawn() { 28 | return _daysOverdrawn; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/moveMethod/AccountType.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.moveMethod; 2 | 3 | public class AccountType { 4 | private String _owner; 5 | 6 | public AccountType(String owner) { 7 | _owner = owner; 8 | } 9 | 10 | double overdraftCharge(int daysOverdrawn) { 11 | if (isPremium()) { 12 | double result = 10; 13 | if (daysOverdrawn > 7) { 14 | result += (daysOverdrawn - 7) * 0.85; 15 | } 16 | return result; 17 | } else { 18 | return daysOverdrawn * 1.75; 19 | } 20 | } 21 | 22 | boolean isPremium() { 23 | switch (_owner) { 24 | case "홍길동": 25 | return true; 26 | default: 27 | return false; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/removeMiddleMan/Department.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.removeMiddleMan; 2 | 3 | public class Department { 4 | private String _chargeCode; 5 | private Person _manager; 6 | 7 | public Department(Person manager) { 8 | _manager = manager; 9 | } 10 | 11 | public Person getManager() { 12 | return _manager; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/kws/seven/after/removeMiddleMan/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.after.removeMiddleMan; 2 | 3 | public class Person { 4 | String _name; 5 | Department _department; 6 | 7 | public Person(String name) { 8 | _name = name; 9 | _department = null; 10 | } 11 | 12 | public Person(String name, Person manager) { 13 | _name = name; 14 | _department = new Department(manager); 15 | } 16 | 17 | public Department getDepartment() { 18 | return _department; 19 | } 20 | 21 | public void setDepartment(Department arg) { 22 | _department = arg; 23 | } 24 | 25 | public String getName() { 26 | return _name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/extractClass/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.extractClass; 2 | 3 | public class Person { 4 | private String _name; 5 | private String _officeAreaCode; 6 | private String _officeNumber; 7 | 8 | public Person(String name, String officeAreaCode, String officeNumber) { 9 | _name = name; 10 | _officeAreaCode = officeAreaCode; 11 | _officeNumber = officeNumber; 12 | } 13 | 14 | public String getName() { 15 | return _name; 16 | } 17 | 18 | public String getTelephoneNumber() { 19 | return ("(" + _officeAreaCode + ")" + _officeNumber); 20 | } 21 | 22 | String getOfficeAreaCode() { 23 | return _officeAreaCode; 24 | } 25 | 26 | void setOfficeAreaCode(String officeAreaCode) { 27 | _officeAreaCode = officeAreaCode; 28 | } 29 | 30 | String getOfficeNumber() { 31 | return _officeNumber; 32 | } 33 | 34 | void setOfficeNumber(String officeNumber) { 35 | _officeNumber = officeNumber; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/hideDelegate/Department.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.hideDelegate; 2 | 3 | public class Department { 4 | private String _chargeCode; 5 | private Person _manager; 6 | 7 | public Department(Person manager) { 8 | _manager = manager; 9 | } 10 | 11 | public Person getManager() { 12 | return _manager; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/hideDelegate/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.hideDelegate; 2 | 3 | public class Person { 4 | String _name; 5 | Department _department; 6 | 7 | public Person(String name) { 8 | _name = name; 9 | _department = null; 10 | } 11 | 12 | public Person(String name, Person manager) { 13 | _name = name; 14 | _department = new Department(manager); 15 | } 16 | 17 | public Department getDepartment() { 18 | return _department; 19 | } 20 | 21 | public void setDepartment(Department arg) { 22 | _department = arg; 23 | } 24 | 25 | public String getName() { 26 | return _name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/inlineClass/Client.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.inlineClass; 2 | 3 | public class Client { 4 | public static void main() { 5 | Person martin = new Person(); 6 | martin.getOfficeTelephone().setAreaCode("781"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/inlineClass/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.inlineClass; 2 | 3 | public class Person { 4 | private String _name; 5 | private TelephoneNumber _officeTelephone = new TelephoneNumber(); 6 | 7 | public String getName() { 8 | return _name; 9 | } 10 | 11 | public String getTelephoneNumber() { 12 | return _officeTelephone.getTelephoneNumber(); 13 | } 14 | 15 | TelephoneNumber getOfficeTelephone() { 16 | return _officeTelephone; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/inlineClass/TelephoneNumber.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.inlineClass; 2 | 3 | public class TelephoneNumber { 4 | 5 | private String _areaCode; 6 | private String _number; 7 | 8 | public String getTelephoneNumber() { 9 | return ("(" + _areaCode + ")" + _number); 10 | } 11 | 12 | String getAreaCode() { 13 | return _areaCode; 14 | } 15 | 16 | void setAreaCode(String arg) { 17 | _areaCode = arg; 18 | } 19 | 20 | String getNumber() { 21 | return _number; 22 | } 23 | 24 | void setNumber(String arg) { 25 | _number = arg; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/introduceForeignMethod/StartDate.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.introduceForeignMethod; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | 6 | public class StartDate { 7 | public Calendar getNextStartDateByCalendar(Calendar previousEnd) { 8 | Calendar newStart = (Calendar)previousEnd.clone(); 9 | newStart.add(Calendar.DAY_OF_MONTH, 1); 10 | return newStart; 11 | } 12 | 13 | public Date getNextStartDateByDate(Date previousEnd) { 14 | Date newStart = new Date(previousEnd.getYear(), previousEnd.getMonth(), previousEnd.getDate() + 1); 15 | return newStart; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/moveField/Account.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.moveField; 2 | 3 | public class Account { 4 | private AccountType _type; 5 | private double _interestRate; 6 | 7 | public Account(String owner) { 8 | _type = new AccountType(owner); 9 | 10 | if (owner.equals("홍길동")) { 11 | _interestRate = 0.3; 12 | } else { 13 | _interestRate = 0.45; 14 | } 15 | } 16 | 17 | 18 | 19 | public double interestForAmount_days(double amount, int days) { 20 | return _interestRate * amount * days / 365; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/moveField/AccountType.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.moveField; 2 | 3 | public class AccountType { 4 | private String _owner; 5 | 6 | public AccountType(String owner) { 7 | _owner = owner; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/moveMethod/Account.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.moveMethod; 2 | 3 | public class Account { 4 | private AccountType _type; 5 | private int _daysOverdrawn; 6 | 7 | public Account(String owner) { 8 | _type = new AccountType(owner); 9 | } 10 | 11 | double overdraftCharge() { 12 | if (_type.isPremium()) { 13 | double result = 10; 14 | if (_daysOverdrawn > 1) { 15 | result += (_daysOverdrawn - 7) * 0.85; 16 | } 17 | return result; 18 | } else { 19 | return _daysOverdrawn * 1.75; 20 | } 21 | } 22 | 23 | public double bankCharge() { 24 | double result = 4.5; 25 | if (_daysOverdrawn > 0) { 26 | result += overdraftCharge(); 27 | } 28 | return result; 29 | } 30 | 31 | public void setDayOverdrawn(int dayOverdrawn) { 32 | _daysOverdrawn = dayOverdrawn; 33 | } 34 | 35 | public int getDayOverdrawn() { 36 | return _daysOverdrawn; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/moveMethod/AccountType.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.moveMethod; 2 | 3 | public class AccountType { 4 | private String _owner; 5 | 6 | public AccountType(String owner) { 7 | _owner = owner; 8 | } 9 | 10 | boolean isPremium() { 11 | switch (_owner) { 12 | case "홍길동": 13 | return true; 14 | default: 15 | return false; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/com/kws/seven/before/removeMiddleMan/Department.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.removeMiddleMan; 2 | 3 | class Department { 4 | private String _chargeCode; 5 | private Person _manager; 6 | 7 | public Department(Person manager) { 8 | _manager = manager; 9 | } 10 | 11 | public Person getManager() { 12 | return _manager; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/kws/seven/before/removeMiddleMan/Person.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.before.removeMiddleMan; 2 | 3 | public class Person { 4 | String _name; 5 | Department _department; 6 | 7 | public Person(String name) { 8 | _name = name; 9 | _department = null; 10 | } 11 | 12 | public Person(String name, Person manager) { 13 | _name = name; 14 | _department = new Department(manager); 15 | } 16 | 17 | public String getName() { 18 | return _name; 19 | } 20 | 21 | public Person getManager() { 22 | return _department.getManager(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/kws/seven/test/extractClass/PsersonTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.extractClass; 2 | 3 | 4 | import com.kws.seven.before.extractClass.Person; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | public class PsersonTest { 9 | 10 | @Test 11 | public void PersonCreationUnitTest() { 12 | // Arrange 13 | String officeTelephone = "(02)6233-0214"; 14 | // Act 15 | Person person = new Person("홍길동", "02", "6233-0214"); 16 | 17 | // Assert 18 | Assert.assertEquals(officeTelephone, person.getTelephoneNumber()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/kws/seven/test/hideDelegate/AfterPersonTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.hideDelegate; 2 | 3 | import com.kws.seven.after.hideDelegate.Person; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class AfterPersonTest { 8 | @Test 9 | public void getManagerTest() { 10 | Person honggildong = new Person("Hong,Gildong"); 11 | Person john = new Person("John", honggildong); 12 | 13 | Person manager = john.getManager(); 14 | 15 | Assert.assertEquals(honggildong.getName(), manager.getName()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/kws/seven/test/hideDelegate/BeforePersonTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.hideDelegate; 2 | 3 | import com.kws.seven.before.hideDelegate.Person; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class BeforePersonTest { 8 | 9 | @Test 10 | public void getManagerTest() { 11 | Person honggildong = new Person("Hong,Gildong"); 12 | Person john = new Person("John", honggildong); 13 | 14 | Person manager = john.getDepartment().getManager(); 15 | 16 | Assert.assertEquals(honggildong.getName(), manager.getName()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/kws/seven/test/introduceForeignMethod/StartDateTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.introduceForeignMethod; 2 | 3 | import com.kws.seven.before.introduceForeignMethod.StartDate; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import java.util.Calendar; 8 | import java.util.Date; 9 | 10 | public class StartDateTest { 11 | @Test 12 | public void getNextStartDateByCalendarUnitTest() { 13 | // Arrange 14 | StartDate startDate = new StartDate(); 15 | 16 | Calendar end1 = Calendar.getInstance(); 17 | end1.set(Calendar.YEAR, 2015); 18 | end1.set(Calendar.MONTH, Calendar.FEBRUARY); 19 | end1.set(Calendar.DAY_OF_MONTH, 28); 20 | 21 | Calendar end2 = Calendar.getInstance(); 22 | end2.set(Calendar.YEAR, 2016); 23 | end2.set(Calendar.MONTH, Calendar.FEBRUARY); 24 | end2.set(Calendar.DAY_OF_MONTH, 28); 25 | 26 | // Act 27 | Calendar start1 = startDate.getNextStartDateByCalendar(end1); 28 | Calendar start2 = startDate.getNextStartDateByCalendar(end2); 29 | 30 | // Assert 31 | Assert.assertEquals(1, start1.get(Calendar.DAY_OF_MONTH)); 32 | Assert.assertEquals(29, start2.get(Calendar.DAY_OF_MONTH)); 33 | } 34 | 35 | @Test 36 | public void getNextStartDateByDate() { 37 | // Arrange 38 | StartDate startDate = new StartDate(); 39 | 40 | Date end1 = new Date(2015, Calendar.FEBRUARY, 28); 41 | Date end2 = new Date(2016, Calendar.FEBRUARY, 28); 42 | 43 | // Act 44 | Date start1 = startDate.getNextStartDateByDate(end1); 45 | Date start2 = startDate.getNextStartDateByDate(end2); 46 | 47 | // Assert 48 | Assert.assertEquals(1, start1.getDate()); 49 | Assert.assertEquals(29, start2.getDate()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/kws/seven/test/moveField/AccountTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.moveField; 2 | 3 | import com.kws.seven.before.moveField.Account; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class AccountTest { 8 | @Test 9 | public void interestForAmount_daysUnitTest() throws Exception { 10 | // Arrange 11 | Account honggildong = new Account("홍길동"); 12 | Account doolry = new Account("둘리"); 13 | Account gogildong = new Account("고길동"); 14 | 15 | double amount = 10000000.0; 16 | int days = 30; 17 | 18 | double premiumInterest = 0.3 * amount * days / 365; 19 | double normalInterest = 0.45 * amount * days / 365; 20 | 21 | // Act 22 | double hongInterest = honggildong.interestForAmount_days(amount, days); 23 | double doolInterest = doolry.interestForAmount_days(amount, days); 24 | double goInterest = gogildong.interestForAmount_days(amount, days); 25 | 26 | // Assert 27 | Assert.assertEquals(premiumInterest, hongInterest, 0.1); 28 | Assert.assertEquals(normalInterest, doolInterest, 0.1); 29 | Assert.assertEquals(normalInterest, goInterest, 0.1); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/kws/seven/test/moveMethod/AccountTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.moveMethod; 2 | 3 | import com.kws.seven.before.moveMethod.Account; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class AccountTest { 8 | @Test 9 | public void bankChargeUnitTest() throws Exception { 10 | // Arrange 11 | Account honggildong = new Account("홍길동"); 12 | Account doolry = new Account("둘리"); 13 | Account gogildong = new Account("고길동"); 14 | 15 | double premiumCharge = 17.05; 16 | double normalCharge = 22.0; 17 | 18 | // Act 19 | honggildong.setDayOverdrawn(10); 20 | doolry.setDayOverdrawn(10); 21 | gogildong.setDayOverdrawn(10); 22 | 23 | double hongCharge = honggildong.bankCharge(); 24 | double doolCharge = doolry.bankCharge(); 25 | double goCharge = gogildong.bankCharge(); 26 | 27 | // Assert 28 | Assert.assertEquals(premiumCharge, hongCharge, 0.01); 29 | Assert.assertEquals(normalCharge, doolCharge, 0.01); 30 | Assert.assertEquals(normalCharge, goCharge, 0.01); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/com/kws/seven/test/removeMiddleMan/AfterPersonTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.removeMiddleMan; 2 | 3 | import com.kws.seven.after.removeMiddleMan.Person; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class AfterPersonTest { 8 | 9 | @Test 10 | public void getManagerTest() { 11 | Person honggildong = new Person("Hong,Gildong"); 12 | Person john = new Person("John", honggildong); 13 | 14 | Person manager = john.getDepartment().getManager(); 15 | 16 | Assert.assertEquals(honggildong.getName(), manager.getName()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/kws/seven/test/removeMiddleMan/BeforePersonTest.java: -------------------------------------------------------------------------------- 1 | package com.kws.seven.test.removeMiddleMan; 2 | 3 | import com.kws.seven.before.removeMiddleMan.Person; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class BeforePersonTest { 8 | @Test 9 | public void getManagerTest() { 10 | Person honggildong = new Person("Hong,Gildong"); 11 | Person john = new Person("John", honggildong); 12 | 13 | Person manager = john.getManager(); 14 | 15 | Assert.assertEquals(honggildong.getName(), manager.getName()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/kws/testFixture/data.txt: -------------------------------------------------------------------------------- 1 | Bradman 99.94 52 80 10 6996 334 29 2 | Pollock 60.97 23 41 4 2256 274 7 3 | Headly 60.83 22 40 4 2256 270* 10 4 | Sutcliffe 60.73 54 84 9 4555 194 16 -------------------------------------------------------------------------------- /src/com/kws/testFixture/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KWSStudy/Refactoring/0c50dc148b2d4c4ac04030803430216a993056e3/src/com/kws/testFixture/empty.txt --------------------------------------------------------------------------------