- Software Engineering (10780)
- ํ๋ฒ: 2021024057
- ์ด๋ฆ: ๊น๋ณ์ค
1. ๋์์ธ ๋ถ์
Design A
Design B
- ์์ ์ ์๋ ๋ ๋์์ธ์ ๋ชจ๋ ๊ณ ๊ฐ(
Customor) ์ ๋ณด๋ฅผ ๊ด๋ฆฌํ๋ ์์คํ ์ Class diagram์ ๋ํ๋ด๊ณ ์์ต๋๋ค. - ํนํ
CustomerListclass์์ ๊ณ ๊ฐ ์ ๋ณด๊ฐ ๋ณ๊ฒฝ๋ ๋ ๋ค๋ฅธ ๋ถ๋ถ(MarketingLetters,CustomerManagementDialog)์ผ๋ก ๋ณ๊ฒฝ๋์์์ ์ ๋ฌํ๋ ๋ฐฉ์์ ์ฐจ์ด๊ฐ ์์์ ํ์ธํ ์ ์์์ต๋๋ค.
| ํน์ง | Design A | Design B |
|---|---|---|
| ๋ณ๊ฒฝ ์๋ฆผ ๋ฐฉ์ | CustomerList๊ฐ ์ง์ ๋ค๋ฅธ class์ method๋ฅผ ํธ์ถ | Observer Pattern ๊ธฐ๋ฐ์ ๊ฐ์ ํธ์ถ |
CustomerList์ ์ญํ | ๊ณ ๊ฐ ๋ฐ์ดํฐ ๊ด๋ฆฌ ๋ฐ UI/๋ง์ผํ ๋ก์ง ์ง์ ์ฒ๋ฆฌ | ๊ณ ๊ฐ ๋ฐ์ดํฐ ๊ด๋ฆฌ ๋ฐ event ์๋ฆผ ์ญํ ๋ง ์ํ |
| Coupling(๊ฒฐํฉ๋) | CustomerList๊ฐ MarketingLetters์ CustomerManagementDialog์ ์ง์ ๊ฒฐํฉ | CustomerList๊ฐ CustomerEventHandler interface์๋ง ๊ฐ์ ๊ฒฐํฉ |
| ํ์ฅ/์ ์ง๋ณด์ | ์๋ก์ด ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ ค๋ฉด CustomerList๋ฅผ ์์ ํด์ผ ํจ | ์๋ก์ด Listener๋ฅผ ์ถ๊ฐํ์ฌ ๊ธฐ๋ฅ ํ์ฅ ๊ฐ๋ฅ |
2. Design principle and pattern-based argue
2.1. (Design Pattern) Observer Pattern
Observer Pattern (a.k.a. "Publish-Subscribe")
"๊ฐ์ฒด ๊ฐ ์ผ๋๋ค ์ข ์์ฑ์ ์ ์ํ์ฌ, ๊ฐ์ฒด์ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋ ๋ชจ๋ ์ข ์ ๊ฐ์ฒด๊ฐ ์๋์ผ๋ก ํต์ง๋ฐ๊ณ ์ ๋ฐ์ดํธ๋๋๋ก ํ๋ค." [1]
- Design B๋ observer pattern์ ๋ช
ํํ๊ฒ ๋ฐ์ํ๊ณ ์์ต๋๋ค.
- Subject:
CustomerList(์ด๋ฒคํธ ๋ฐ์ ์ observer๋ค์๊ฒ ์๋ฆผ) - Observer:
CustomerEventHandlerinterface๋ฅผ ๊ตฌํํ๋MarketingLetters์CustomerListListener(์ด๋ฒคํธ ์์ ๋ฐ ์ฒ๋ฆฌ) CustomerList๋ ์ด๋ค class๊ฐ ์์ ์ ์ด๋ฒคํธ๋ฅผ ์์ ํ๊ฒ ๋๋์ง ์ ํ์๊ฐ ์์ต๋๋ค.- Event๋ฅผ
handler์๊ฒ ์ ํํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.- ์ด๋ Loose Coupling ์กฐ๊ฑด์ ์ถฉ์กฑํฉ๋๋ค.
- Subject:
2.2. (Design Principle) Single Responsibility Principle(SRP)
"๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ์์ ๋จ์ผ ์ฑ ์ ์์น(single responsibility principle)์ด๋ ๋ชจ๋ ํด๋์ค๋ ํ๋์ ์ฑ ์๋ง ๊ฐ์ง๋ฉฐ, ํด๋์ค๋ ๊ทธ ์ฑ ์์ ์์ ํ ์บก์ํํด์ผ ํจ์ ์ผ์ปซ๋๋ค. ํด๋์ค๊ฐ ์ ๊ณตํ๋ ๋ชจ๋ ๊ธฐ๋ฅ์ ์ด ์ฑ ์๊ณผ ์ฃผ์ ๊น๊ฒ ๋ถํฉํด์ผ ํ๋ค." [2]
- Design A
CustomerList๊ฐ ๊ฐ์ง๊ณ ์๋ responsibility๋ค- ๊ณ ๊ฐ ๋ฆฌ์คํธ ๊ด๋ฆฌ (
customers.add(customer)) - ๋ง์ผํ
ํธ์ง ๋ฐ์ก ์ฒ๋ฆฌ (
marketing.customerAdded(customer)) - UI ๋ฆฌ์คํธ ์
๋ฐ์ดํธ ์ฒ๋ฆฌ (
gui.list.add(customer.name))
- ๊ณ ๊ฐ ๋ฆฌ์คํธ ๊ด๋ฆฌ (
- ์ด๋ SRP ์๋ฐ์ ํด๋นํฉ๋๋ค.
- Design B
CustomerList๋ ๊ณ ๊ฐ ๋ฆฌ์คํธ ๊ด๋ฆฌ ๋ฐ ์ด๋ฒคํธ ๋ฐ์ ์๋ฆผ์ด๋ผ๋ single responsibility๋ง ๊ฐ์ง๋๋ค.- ๋ง์ผํ
๊ด๋ จ ์ฑ
์์
MarketingLetters์, UI ์ ๋ฐ์ดํธ ๊ด๋ จ ์ฑ ์์CustomerListListener๋ฅผ ๊ตฌํํ๋ class์ ๋ถ๋ฆฌ๋์ด ์์ต๋๋ค. - ์ด๋ SRP๋ฅผ ๋ง์กฑ์ํจ๋ค๊ณ ํ ์ ์์ต๋๋ค.
2.3. (Design Pattern) Open-Closed Principle (OCP)
"๊ฐ๋ฐฉ-ํ์ ์์น(OCP, Open-Closed Principle)์ '์ํํธ์จ์ด ๊ฐ์ฒด(ํด๋์ค, ๋ชจ๋, ํจ์ ๋ฑ๋ฑ)๋ ํ์ฅ์ ๋ํด ์ด๋ ค ์์ด์ผ ํ๊ณ , ์์ ์ ๋ํด์๋ ๋ซํ ์์ด์ผ ํ๋ค'๋ ํ๋ก๊ทธ๋๋ฐ ์์น์ด๋ค." [3]
- Design A
- ๊ณ ๊ฐ ์ถ๊ฐ ์ ๋ค๋ฅธ ์์
์ ์ถ๊ฐํ๋ ค๋ฉด (
Accounting๋ชจ๋์ ์๋ฆผ ๋ณด๋ด๊ธฐ ๋ฑ),CustomerListclass์addCustomer()method๋ฅผ ์์ ํด์ผ ํฉ๋๋ค. (๊ธฐ๋ฅ ์ถ๊ฐ์ ๋ํด closed๋์ง ์์)
- ๊ณ ๊ฐ ์ถ๊ฐ ์ ๋ค๋ฅธ ์์
์ ์ถ๊ฐํ๋ ค๋ฉด (
- Design B
- ์๋ก์ด listener(์:
AccountingListener)๋ฅผ ์ถ๊ฐํ๊ณCustomerList์ ๋ฑ๋กํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค. CustomerList์์ฒด์ ์ฝ๋๋ ์์ ํ ํ์๊ฐ ์์ต๋๋ค. (ํ์ฅ์ ๋ํด open, ์์ ์ ๋ํด closed)- ์ด๋ OCP๋ฅผ ๋ง์กฑ์ํจ๋ค๊ณ ํ ์ ์์ต๋๋ค.
- ์๋ก์ด listener(์:
2.4. (Design Principle) Dependency Inversion Principle (DIP)
"์์กด๊ด๊ณ ์ญ์ ์์น์ ์ํํธ์จ์ด ๋ชจ๋๋ค์ ๋ถ๋ฆฌํ๋ ํน์ ํ์์ ์ง์นญํ๋ค. ์ด ์์น์ ๋ฐ๋ฅด๋ฉด, ์์ ๊ณ์ธต(์ ์ฑ ๊ฒฐ์ )์ด ํ์ ๊ณ์ธต(์ธ๋ถ ์ฌํญ)์ ์์กดํ๋ ์ ํต์ ์ธ ์์กด๊ด๊ณ๋ฅผ ๋ฐ์ (์ญ์ )์ํด์ผ๋ก์จ ์์ ๊ณ์ธต์ด ํ์ ๊ณ์ธต์ ๊ตฌํ์ผ๋ก๋ถํฐ ๋ ๋ฆฝ๋๊ฒ ํ ์ ์๋ค. ์ด ์์น์ ๋ค์๊ณผ ๊ฐ์ ๋ด์ฉ์ ๋ด๊ณ ์๋ค." [4]
- ์์ ๋ชจ๋์ ํ์ ๋ชจ๋์ ์์กดํด์๋ ์๋๋ค. ์์ ๋ชจ๋๊ณผ ํ์ ๋ชจ๋ ๋ชจ๋ ์ถ์ํ์ ์์กดํด์ผ ํ๋ค.
- ์ถ์ํ๋ ์ธ๋ถ ์ฌํญ์ ์์กดํด์๋ ์๋๋ค. ์ธ๋ถ์ฌํญ์ด ์ถ์ํ์ ์์กดํด์ผ ํ๋ค.

- Design A
- High-level module์ธ
CustomerList๊ฐ low-level moudule์ธ detailํMarketingLetters์CustomerManagementDialog์ ์ง์ ์์กดํ๊ณ ์์ต๋๋ค. (detailํ ๊ฒ์ ์์กด)
- High-level module์ธ
- Design B
CustomerList๋ ์ถ์ํ๋CustomerEventHandlerinterface์๋ง ์์กดํฉ๋๋ค.- detailํ ๊ตฌํ์ฒด(Listener)์ ๋ํ ์์กด์ฑ์ ์ญ์ ์ํต๋๋ค. (์ถ์์ ์ธ ๊ฒ์ ์์กด)
- ์ด๋ DIP๋ฅผ ๋ง์กฑ์ํจ๋ค๊ณ ํ ์ ์์ต๋๋ค.
3. Conclusion
- Design B๋ observer pattern์ ์ฌ์ฉํ์ฌ SRP, OCP, DIP์ ๊ฐ์ ํต์ฌ ๋์์ธ ์์น์ ์ค์ํ๊ณ ์์ต๋๋ค.
- ์ด๋ฅผ ํตํด
- ๊ฒฐํฉ๋๋ ๋ฎ์ถ๊ณ (๋์จํ ๊ฒฐํฉ, low coupling)
- ์์ง๋๋ ๋์ด๋ฉฐ
- ํ์ฅ์ฑ๊ณผ ์ ์ฐ์ฑ์ ๊ทน๋ํํ์ฌ
- ์์คํ ์ ์ ์ง๋ณด์์ฑ์ ํฅ์์ํฌ ์ ์์ต๋๋ค.
์ด๋ฌํ ์ด์ ๋ก, Design B๊ฐ ๋ ์ฐ์ํ ์ํํธ์จ์ด ๋์์ธ์ด๋ผ๊ณ ํ๊ฐํ ์ ์์ต๋๋ค.
4. Works Cited
[1] ์์ ๊ฐ์์๋ฃ, Design Patterns (https://learning.hanyang.ac.kr/courses/181214/modules/items/8362823?return_url=/courses/181214/external_tools/140)
[2] Wikipedia, "Single-Responsibility Principle" (https://en.wikipedia.org/wiki/Single-responsibility_principle)
[3] Wikipedia, "Open-Closed Principle" (https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle)
[4] Wikipedia, "Dependency Inversion Principle" (https://en.wikipedia.org/wiki/Dependency_inversion_principle)




