Object-Oriented Design
From Requirements to Code
- ์ฌ์ฉ์ ์๊ตฌ์ฌํญ (Requirements)
- ๊ธฐ์ ? Code
From Problem to Solution
- Problem Space (Domain Model)
- ์ค์ ์ธ๊ณ์ ๊ฐ๋
- ์๊ตฌ์ฌํญ, ๊ฐ๋
- ๊ฐ๋ ๊ฐ์ ๊ด๊ณ
- ๋ฌธ์ ํด๊ฒฐ
- ์ดํ ๊ตฌ์ถ
- Solution Space (Object Model)
- ์์คํ ๊ตฌํ
Classes,objectsObjects๊ฐ์ ์ฐธ์กฐ ๋ฐ ์์ ๊ณ์ธต- ๊ฒฐ๊ณผ ๊ณ์ฐ
- ํด๊ฒฐ์ฑ ์ฐพ๊ธฐ
An Object-Oriented Design Process
- OO Analysis: ๋ฌธ์ ์ดํด
- ๋ฌธ์ model / diagram ํ, ๊ฐ๋ ์ ์
- Domain model (a.k.a. conceptual model), ์ฉ์ด์ง
- OO Design: ํด๊ฒฐ์ฑ
์ ์
- ์์คํ ํ๋ ์ ์
- ์์คํ sequence diagram
- ์์คํ ํ๋ ๊ณ์ฝ
- ๊ฐ์ฒด ์ฑ ์ ํ ๋น, ์ํธ์์ฉ ์ ์
- ๊ฐ์ฒด interaction diagrams
- ์ ์ฌ์ ํด๊ฒฐ์ฑ model / diagram ํ
- Object model
Learning Goals
- Solution Space์์์ UML
- Object diagrams: ๊ฐ๋ ์์ classes๋ก
- Interaction diagrams: ์์คํ ๊ฒฝ๊ณ๋ฅผ ๋์ด์๋ ์ํธ์์ฉ
- ์ค๊ณ ๊ฒฐ์ (Design Decisions)
- ์์น, patterns, heuristics ์ดํ ํ์ฅ
- GRASP patterns๋ฅผ ์ ์ฉํ ์ค๊ณ ์ฑ ์ ํ ๋น
- ์ค๊ณ ๊ฐ์ tradeoffs ์ถ๋ก
- Coupling ๋ฐ
cohesion๊ด์ ์์์ tradeoffs ๋ ผ์
Modeling Implementations with UML
A Word on UML
- UML์ ํ์คํ๋, ํ๋ฆฝ๋ ํ๊ธฐ๋ฒ
- ๋๋ถ๋ถ์ software engineers๊ฐ ์ฝ์ ์ ์๊ณ , ๋ง์ ๋๊ตฌ๋ค์ด ์ง์
- ์์์ ์ค๋ฌด์๋ค๋ง์ด ์๊ฒฉํ๊ฒ ์ฌ์ฉ
- ์ผ๋ฐ์ ์ผ๋ก ์ค์ผ์น, ์ปค๋ฎค๋์ผ์ด์ , ๋ฌธ์ํ, (์๋ง๋) ๋ฒฝ ์ฅ์์ฉ์ผ๋ก ๋น๊ณต์์ ์ฌ์ฉ
- ์ปค๋ฎค๋์ผ์ด์
์ ์ํด UML ์ฌ์ฉ
- ํ๊ธฐ๋ฒ์ ๋ค์ ์๊ฒฉํ๊ฒ ๋ฐ๋ฅด์ง๋ง, ๋ชจ๋ ์ธ๋ถ ์ฌํญ์ ์๋
One Domain Model for the Library System

From Concepts to Objects
- Domain ๊ฐ๋
์ classes์ ์ด๋ป๊ฒ ๋ค๋ฅธ๊ฐ?
- ๋ชจ๋ ๊ฐ๋ ์ด class๊ฐ ๋์ด์ผ ํ๋๊ฐ?
- ๋ชจ๋ class๊ฐ ๊ฐ๋ ์ ๋ํ๋ด์ผ ํ๋๊ฐ?
Object Diagrams
- Fields์ methods๋ฅผ ๊ฐ์ง Objects/classes
- Methods๋ฅผ ๊ฐ์ง Interfaces
- Associations, visibility, types

Object Diagram Notation: Classes/Objects

class LibraryAccount {
id: int;
lateFees: int;
boolean borrow(Book b) { ... }
void returnItem(Book b) { ... }
void payFees(int payment) { ... }
}
Object Diagram Notation: Interfaces

interface LibraryAccount {
boolean borrow(Book b);
void returnItem(Book b);
void payFees(int payment);
}
Object Diagram Notation: Associations

class LibraryAccount {
...
List<Book> borrowedBooks;
}
class Book {
...
LibraryAccount borrowedBy;
}
- Fields๋ฅผ associations ๋์ ๋๋ ์ถ๊ฐ๋ก ์ฌ์ฉํ์ง ๋ง ๊ฒ
- Fields๋ ๊ธฐ๋ณธ types์๋ง ์ฌ์ฉ

Class Diagram vs Object Diagram
- Classes์ objects ๋ ๋ค modeling ๊ฐ๋ฅ
- ์ฉ์ด๋ ์ข ์ข ํผ์ฉ๋จ
- ํน์ objects๋ฅผ modelingํด์ผ ํ๋ ๊ฒฝ์ฐ
objectId: Classํ๊ธฐ๋ฒ ์ฌ์ฉ
Class Diagrams and JavaScript/TypeScript
- Classes๋ฅผ ์ฌ์ฉํ์ง ์์ ๋์๋, ๋์ผํ ์์ด๋์ด๋ฅผ ํํํ๊ธฐ ์ํด ํ๊ธฐ๋ฒ ์ฌ์ฉ
- ๋์ผํ shape์ ๊ณต์ ํ๋ ๋ง์ objects
- TypeScript interfaces๋ class diagram ํ๊ธฐ๋ฒ๊ณผ ์ผ์น
function newLibraryAccount(id, lateFees) {
return {
borrow: function (book) { ... },
returnItem: function (book) { ... },
payFees: function (payment) { ... }
}
}
One Object Model for the Library System

Domain Model vs Object Model

Object Diagram Notation Requirements
- ํ๊ธฐ๋ฒ์ ๋ํด ๋งค์ฐ ์๊ฒฉํ์ง๋ ์์ง๋ง,
- Classes/objects, interfaces, concepts์ ์ ํฉํ 2 ๋๋ 3 ๋ถ๋ถ์ผ๋ก ๋ ์์ ์ฌ์ฉ
- Fields์ methods์ types ํฌํจ
- ์ ์ ํ ๊ฒฝ์ฐ fields๊ฐ ์๋ associations ์ฌ์ฉ
- Association ์ด๋ฆ๊ณผ cardinalities ์ฌ์ฉ
- "is-a"(์์ ๊ด๊ณ)๋ฅผ ์ ์ธํ ํ์ดํ ํ์ ์ ํฌ๊ฒ ์ ๊ฒฝ ์ฐ์ง ์์
Modeling Interactions Past the System Boundary
- Use case scenario: ๋์๊ด ํ์์ด ๋์๊ด ์นด๋๋ฅผ ์ฌ์ฉํ์ฌ ๋์๊ด ์์คํ ํค์ค์คํฌ์์ ๋ก๊ทธ์ธํ๊ณ ์ฑ ์ ๋์ถ
- ํ์์ด ๋ฏธ๋ฉ ์ฐ์ฒด๋ฃ๊ฐ ์๋์ง ํ์ธํ ํ, ๋์๊ด ์์คํ ์ ํ์ฌ ๋ ์ง์ ๋์ฌ ๊ธฐ๊ฐ์ ๋ํด ์ฑ ์ ๋ฐ๋ฉ ๊ธฐํ์ ๊ฒฐ์
- ํด๋น ์ฑ
๊ณผ ๋ฐ๋ฉ ๊ธฐํ์ ํ์์ ๋์๊ด ๊ณ์ ์ ๋์ถ ํญ๋ชฉ์ผ๋ก ๊ธฐ๋ก

Interaction Diagrams
- Objects ๊ฐ์ ์ํธ์์ฉ
- ๋ ๊ฐ์ง ์ผ๋ฐ์ ์ธ ํ๊ธฐ๋ฒ: sequence diagrams, communication diagrams
- Sequence diagrams๋ system sequence diagrams์ ์ ์ฌํ์ง๋ง, objects/classes ๊ฐ์ ์ํธ์์ฉ์ ๋ฌ์ฌ

Example

Interaction Diagram Practice
- Use case scenario: ...์ฑ
์ ๋์ถ. ํ์์ ๋ฏธ๋ฉ ์ฐ์ฒด๋ฃ๊ฐ ์๋์ง ํ์ธ ํ, ์์คํ
์ ๋์ถ ๊ธฐ๊ฐ(loan period)์ ํ์ฌ ๋ ์ง์ ๋ํด ๋ฐ๋ฉ ๊ธฐํ์ ๊ฒฐ์ ํ๊ณ , ์ฑ
๊ณผ ๋ฐ๋ฉ ๊ธฐํ์ ํ์ ๊ณ์ ์ ๋์ถ ํญ๋ชฉ์ผ๋ก ๊ธฐ๋ก

Interaction Diagrams Help Evaluate Design Alternatives
- ์ค๊ณ ๋์์ ๋ช ์์ ์ผ๋ก ๊ณ ๋ ค
- ๊ฐ ๋์์ ๋ํด, ์ค๊ณ ์ ํ์ ์ํด ์์๋๋ ์ํธ์์ฉ ์ค์ผ์น
- ์ํธ์์ฉ์ components์ APIs์ ํด๋น
Object-Level Design
Who is Responsible?
- ๋์๊ด ๋ฌธ์ (Library problem) ๊ณ ๋ ค
- ์ด๋ class๊ฐ ์ฌ์ฉ์๊ฐ ๋์ถํ ํญ๋ชฉ์ ์์์ผ ํ๋๊ฐ
- ์ด๋ class๊ฐ ์ฐ์ฒด๋ฃ๋ฅผ ๊ณ์ฐํด์ผ ํ๋๊ฐ
Doing and Knowing Responsibilities
- ์ฑ ์(Responsibilities)์ ๊ฐ์ฒด์ ํ๋ ์ธก๋ฉด์์์ ์๋ฌด์ ๊ด๋ จ
- Doing responsibilities (์ํ ์ฑ
์)
- ๊ฐ์ฒด ์์ฑ ๋๋ ๊ณ์ฐ ์ํ ๋ฑ ๋ฌด์ธ๊ฐ๋ฅผ ์ง์ ์ํ
- ๋ค๋ฅธ objects์ ํ๋ ๊ฐ์
- ๋ค๋ฅธ objects์ ํ๋ ์ ์ด ๋ฐ ์กฐ์
- Knowing responsibilities (์ ๋ณด ์ฑ
์)
- Private ์บก์ํ๋ data์ ๋ํด ์๊ธฐ
- ๊ด๋ จ๋ objects์ ๋ํด ์๊ธฐ
- ํ์ํ๊ฑฐ๋ ๊ณ์ฐํ ์ ์๋ ๊ฒ๋ค์ ๋ํด ์๊ธฐ
- Object design์ domain modeling๋งํผ ๋ช
ํํ์ง ์์
- Domain modeling์ ๊ณผ์ ๋ ๋งค์ฐ ์ ๋ฐํด์ง๋ ๊ฒ
- ๊ตฌํ์ ๊ฐ๊น์์ง์๋ก ์ ํ ํ์ (Data, methods ๋ฐฐ์น ๋ฑ)
- ์ค์ ์ธ๊ณ ๊ฐ๋ ๊ณผ ๊ฒฐ์ฝ 1:1์ด ์๋
- ์ฑ
์ ํ ๋น(Assigning Responsibilities)์ ๋ํ ๊ณ ์ฐฐ์ด ๋์๋จ
- ๋์์ธ ์์น๊ณผ heuristics์ ์์กด
- GRASP (General Responsibility Assignment Software Patterns/Principles์ ๋๋ถ๋ถ ํฌํจ
GRASP์ 9๊ฐ ํจํด
- Information expert
- Creator
- Controller
- Indirection
- Low coupling
- High cohesion
- Polymorphism
- Protected variations
- Pure fabrication
Information Expert
| Name | Information Expert |
|---|---|
| Problem | ๊ฐ์ฒด์ ์ฑ ์์ ํ ๋นํ๋ ๊ธฐ๋ณธ ์์น์ ๋ฌด์์ธ๊ฐ? |
| Solution | ์ฑ ์์ ์ํํ๋ ๋ฐ ํ์ํ ์ ๋ณด๋ฅผ ๊ฐ์ง class์ ์ฑ ์์ ํ ๋น |
Applying Information Expert
- Software
Board๋ ๋ชจ๋Squareobjects๋ฅผ ์งํฉ(aggregate)์ํฌ ๊ฒ - ๋ฐ๋ผ์,
Board๋ ์ด ์ฑ ์์ ์ํํ๋ ๋ฐ ํ์ํ ์ ๋ณด๋ฅผ ๊ฐ์ง
Creator
| Name | Creator |
|---|---|
| Problem | ๋๊ฐ A๋ฅผ ์์ฑํ๋๊ฐ? |
| Solution | ๋ค์ ์ค ํ๋ ์ด์์ด ์ฐธ(๋ง์์๋ก ์ข์)์ผ ๊ฒฝ์ฐ, class B์ class A์ instance ์์ฑ ์ฑ
์์ ํ ๋น B๊ฐ A๋ฅผ "ํฌํจ"ํ๊ฑฐ๋ ๋ณตํฉ์ ์ผ๋ก aggregate ํจ B๊ฐ A๋ฅผ ๊ธฐ๋กํจ B๊ฐ A๋ฅผ ๊ธด๋ฐํ๊ฒ ์ฌ์ฉํจ B๊ฐ A ์์ฑ์ ์ํ ์ด๊ธฐํ data๋ฅผ ๊ฐ์ง |
Example: Creator

- Dynamic model์์ Creator pattern ์ ์ฉ
- Design Model์ DCD์์,
Board๋Squares์ composite aggregation association์ ๊ฐ์ง- Static model์ Creator ์ ์ฉ ์ค
Controller
| Name | Controller |
|---|---|
| Problem | UI layer๋ฅผ ๋์ด system operation์ ์์ ํ๊ณ ์กฐ์ ("์ ์ด")ํ๋ ์ฒซ ๋ฒ์งธ ๊ฐ์ฒด๋ ๋ฌด์์ธ๊ฐ? |
| Solution | ๋ค์ ์ ํ์ง ์ค ํ๋๋ฅผ ๋ํ๋ด๋ ๊ฐ์ฒด์ ์ฑ
์ ํ ๋น ์ ์ฒด "system", "root object", software๊ฐ ์คํ ์ค์ธ device ๋๋ ์ฃผ์ subsystem (๋ชจ๋ facade controller์ ๋ณํ) System operation์ด ๋ฐ์ํ๋ use case scenario (use case ๋๋ session controller) |

MonopolyGame์ ์ฌ์ฉํ Controller pattern ์ ์ฉ- UI layer์ software objects์ domain layer ์ฐ๊ฒฐ
Design Goals, Principles, and Patterns
- Design Goals
- ๋ณ๊ฒฝ, ์ดํด, ์ฌ์ฌ์ฉ, ๋ถ์ ๋ฑ์ ์ํ ์ค๊ณ
- Design Principle
- Low coupling
- high cohesion
- Low representational gap
- Design Heuristics
- Law of Demeter
- Information expert
- Creator
- Controller

Design Principle: Low Representational Gap
2025.11.5.(๋ชฉ)
Low Representational Gap
- ์๋ณ๋ ๊ฐ๋ ์ ๊ตฌํ ์ classes์ ๋ํ ์๊ฐ์ ์ ๊ณต
- Domain ๊ฐ๋ ์ ๋ฐ์ํ๋ Classes๋ ์ข ์ข ์ดํดํ๊ธฐ ์ง๊ด์ ์ด๋ฉฐ, ๊ฑฐ์ ๋ณ๊ฒฝ๋์ง ์์ (low representational gap)
Designs with Low Representational Gap
- ๊ฐ domain class์ ๋ํด software class ์์ฑ, ํด๋น ๊ด๊ณ ์์ฑ
- Design goal: ๋ณ๊ฒฝ์ ์ํ ์ค๊ณ
- ์ด๊ฒ์ ๋จ์ง ์์์
- ๋ชจ๋ domain classes๊ฐ software ๋์๋ฌผ์ ํ์๋ก ํ์ง๋ ์์
- Pure fabrications๊ฐ ํ์ํ ์ ์์
- ๋ค๋ฅธ ์์น๋ค์ด ์ข ์ข ๋ ์ค์
Design Principle: Low Coupling
- Module์ ๊ฐ๋ฅํ ํ ์ ์ ์์ ๋ค๋ฅธ modules์ ์์กดํด์ผ ํจ
- ์ดํด๋ ํฅ์ (์ดํด๋ฅผ ์ํ ์ค๊ณ)
- Context์ ๋ํ ์ ํ๋ ์ดํด, ๊ณ ๋ฆฝ๋ ์ํ์์ ์ดํด ์ฉ์ด
- ๋ณ๊ฒฝ ๋น์ฉ ๊ฐ์ (๋ณ๊ฒฝ์ ์ํ ์ค๊ณ)
- ๋ณ๊ฒฝ์ ํ์ํ context๊ฐ ์ ์
- Module interface ๋ณ๊ฒฝ ์, ์ํฅ์ ๋ฐ๋ modules๊ฐ ์ ์ (ํ๊ธ ํจ๊ณผ ๊ฐ์)
- ์ฌ์ฌ์ฉ์ฑ ํฅ์ (์ฌ์ฌ์ฉ์ ์ํ ์ค๊ณ)
- ์์กด์ฑ์ด ์ ์ด ์๋ก์ด context์ ์ ์ ์ฉ์ด
- ์ดํด๋ ํฅ์ (์ดํด๋ฅผ ์ํ ์ค๊ณ)
Topologies with Different Coupling
Types of module interconnection structures

High Coupling is Undesirable
- Low coupling์ ๊ฐ์ง element๋ ์ ์ ์์ ๋ค๋ฅธ elements์ ์์กด
- Elements == classes, subsystems, ...
- "์ ์"์ context์ ๋ฐ๋ผ ๋ค๋ฆ
- High coupling์ ๊ฐ์ง class๋ ๋ง์ ๋ค๋ฅธ classes์ ์์กด
- ๊ด๋ จ๋ classes์ ๋ณ๊ฒฝ์ด ๋ก์ปฌ ๋ณ๊ฒฝ์ ๊ฐ์ ; ๋ก์ปฌ class์ ๋ณ๊ฒฝ์ด ๊ด๋ จ๋ classes์ ๋ณ๊ฒฝ์ ๊ฐ์ (์ทจ์ฝํจ, ํ๊ธ ํจ๊ณผ)
- ๊ณ ๋ฆฝ๋ ์ํ์์ ์ดํดํ๊ธฐ ์ด๋ ค์
- ๋ค๋ฅธ ์์กด์ classes์ ์ถ๊ฐ์ ์ธ ์กด์ฌ๋ฅผ ์๊ตฌํ๋ฏ๋ก ์ฌ์ฌ์ฉํ๊ธฐ ์ด๋ ค์
- ํ์ฅํ๊ธฐ ์ด๋ ค์ โ ๋ง์ ๊ณณ์์ ๋ณ๊ฒฝ ํ์
Design Goals, Principles, and Patterns
- Design Goals: ๋ณ๊ฒฝ, ์ดํด, ์ฌ์ฌ์ฉ, ๋ถ์ ๋ฑ์ ์ํ ์ค๊ณ
- Design Principle: Low coupling, high cohesion, Low representational gap
- Design Heuristics: (์์คํ ์์ ์์น ์ฆ์ง) Law of Demeter, Information expert, Creator, Controller
Design Heuristic: Law of Demeter
- ๊ฐ module์ ๋ค๋ฅธ units์ ๋ํด ์ ํ๋ ์ง์๋ง ๊ฐ์ ธ์ผ ํจ: ํ์ฌ unit๊ณผ "๋ฐ์ ํ๊ฒ" ๊ด๋ จ๋ units๋ง
- ํนํ: ๋ฏ์ ์ด์๊ฒ ๋ง ๊ฑธ์ง ๋ง ๊ฒ (Donโt talk to strangers!)
- ์:
a.getB().getC().foo()๊ธ์ง
for (let i of shipment.getBox().getItems())
shipmentWeight += i.getWeight() ...
So don't do this ^ !!
Coupling: Discussion
- ๋งค์ฐ ์์ ์ ์ธ elements์ ๋ํ high coupling์ ๋ณดํต ๋ฌธ์ ๋์ง ์์
- ์์ ์ ์ธ interface๋ ๋ณ๊ฒฝ๋ ๊ฐ๋ฅ์ฑ์ด ๋ฎ๊ณ , ์ ์ดํด๋จ
- Implementations์ ๋ํ coupling๋ณด๋ค interfaces์ ๋ํ coupling ์ ํธ
- Subclass/superclass coupling์ ํนํ ๊ฐ๋ ฅํจ
- Protected fields์ methods๊ฐ ๋ ธ์ถ๋จ
- Subclass๋ ๋ง์ superclass ๋ณ๊ฒฝ(์: method signatures ๋ณ๊ฒฝ, abstract methods ์ถ๊ฐ)์ ์ทจ์ฝ
- Guideline: Coupling์ ์ค์ด๊ธฐ ์ํด, ์์(inheritance)๋ณด๋ค composition ์ ํธ
- Coupling์ ๋ง์ ์์น ์ค ํ๋
- Cohesion, low repr. gap ๋ฐ ๊ธฐํ ์์น๋ ๊ณ ๋ ค
Design Goals
- Low coupling์ด ์ง์ํ๋ ๋ฐฉ์ ์ค๋ช
:
- Design for change (๋ณ๊ฒฝ์ ์ํ ์ค๊ณ)
- ๋ ์ ์ ์์ ๋ค๋ฅธ objects์ ๋ํ ์์กด์ฑ์ผ๋ก ๋ณ๊ฒฝ์ด ๋ ์ฌ์
- ๋ณ๊ฒฝ์ด ํ๊ธ ํจ๊ณผ(rippling effects)๋ฅผ ๊ฐ์ง ๊ฐ๋ฅ์ฑ ๊ฐ์
- Design for understandability (์ดํด๋ฅผ ์ํ ์ค๊ณ)
- ์ดํดํด์ผ ํ ์์กด์ฑ์ด ์ ์ (์:
a.getB().getC().foo())
- ์ดํดํด์ผ ํ ์์กด์ฑ์ด ์ ์ (์:
- Design for division of labor (๋ถ์
์ ์ํ ์ค๊ณ)
- ๋ ์์ interfaces, ๋ถํ ์ฉ์ด
- Design for reuse (์ฌ์ฌ์ฉ์ ์ํ ์ค๊ณ)
- ๋ณต์กํ ์์กด์ฑ ์์ด ์ฌ์ฌ์ฉ ์ฉ์ด
- Design for change (๋ณ๊ฒฝ์ ์ํ ์ค๊ณ)
Design Heuristic: Controller (also Design Pattern: FAรADE)
- Problem: ์ด๋ค ๊ฐ์ฒด๊ฐ system operation (event)์ ์์ ํ๊ณ ์กฐ์ ํ๋๊ฐ?
- Solution: ๋ค์์ ๋ํ๋ด๋ ๊ฐ์ฒด์ ์ฑ
์ ํ ๋น
- ์ ์ฒด system, device, ๋๋ subsystem (faรงade controller)
- System event๊ฐ ๋ฐ์ํ๋ use case scenario (use case controller)
- Process: System sequence diagram์์ ๋์ถ (ํต์ฌ ์์น: Low representational gap, high cohesion)
- (๋ค์ด์ด๊ทธ๋จ 53, 54 ๋ด์ฉ ํฌํจ)
Controller: Discussion
Controller๋ coordinator- ๋ง์ ์์ ์ ์ง์ ์ํํ์ง ์์
- ๋ค๋ฅธ objects์ ์์
- Faรงade controllers๋ system events๊ฐ "๋๋ฌด ๋ง์ง" ์์ ๋ ์ ํฉ
- ์์คํ ์ ์ํ ํ๋์ ์ ์ฒด controller
- Use case controller๋ faรงade controller๊ฐ ๊ณผ๋ํ ์ฑ
์์ผ๋ก "๋น๋ํด์ง" ๋(low cohesion, high coupling) ์ ํฉ
- ํน์ ์์ ์ ์ํ ์ฌ๋ฌ ๊ฐ์ ์์ controllers
- Faรงade design pattern (์ถํ ๊ฐ์)๊ณผ ๋ฐ์ ํ๊ฒ ๊ด๋ จ๋จ
Controller: Design Tradeoffs
- Coupling ๊ฐ์
- User interface์ domain logic์ด ์๋ก ๋ถ๋ฆฌ๋จ (decoupled)
- ์ดํด๋: ๊ณ ๋ฆฝ๋ ์ํ์์ ์ดํด ๊ฐ๋ฅ, ๋ค์์ผ๋ก ์ด์ด์ง:
- Evolvability (์งํ ์ฉ์ด์ฑ): UI์ domain logic ๋ชจ๋ ๋ณ๊ฒฝ ์ฉ์ด
- ๋ ๋ค
controller์ ๊ฒฐํฉ(coupled)๋์ด,controller๊ฐ ์ค์ฌ์(mediator) ์ญํ . ์ด coupling์ ๋ ํด๋ก์ Controller๋ ๋ ์๊ณ ์์ ์ ์ธ interface- Domain logic ๋ณ๊ฒฝ์ด UI๊ฐ ์๋
controller์ ์ํฅ - Domain logic design์ ๋ชฐ๋ผ๋ UI ๋ณ๊ฒฝ ๊ฐ๋ฅ
- ๋ ๋ค
- ์ฌ์ฌ์ฉ์ฑ ์ง์
Controller๋ domain logic์ ๋ํ interface ์ญํ- ๋ ์๊ณ ๋ช ์์ ์ธ interfaces๋ evolvability ์ง์
- ๋จ, ๋น๋ํด์ง(bloated) controllers๋ coupling์ ๋์ด๊ณ
cohesion์ ๋ฎ์ถค; ํด๋น ์ ๋ถํ
Design Principle: High Cohesion (OR SINGLE RESPONSIBILITY PRINCIPLE)
๋์ ์์ง๋
Design Principle: Cohesion
- Module์ ์๊ณ ๊ด๋ จ๋ ์ฑ
์ ์งํฉ์ ๊ฐ์ ธ์ผ ํจ
- ์ดํด๋ ํฅ์ (์ดํด๋ฅผ ์ํ ์ค๊ณ)
- ์์ ์ฑ ์ ์งํฉ์ด ์ดํดํ๊ธฐ ๋ ์ฌ์
- ์ฌ์ฌ์ฉ์ฑ ํฅ์ (์ฌ์ฌ์ฉ์ ์ํ ์ค๊ณ)
- ์์ง๋ ฅ ์๋(cohesive) ์ฑ ์ ์งํฉ์ ๋ค๋ฅธ application์์ ์ฌ๋ฐ์ํ ๊ฐ๋ฅ์ฑ์ด ๋์
- ์ดํด๋ ํฅ์ (์ดํด๋ฅผ ์ํ ์ค๊ณ)
Example: Low Cohesion
class DatabaseApplication {
public void authorizeOrder(Data data, User currentUser, ...){
// check authorization
// lock objects for synchronization
// validate buffer
// log start of operation
// perform operation
// log end of operation
// release lock on objects
}
public void startShipping(OtherData data, User currentUser, ...){
// check authorization
// lock objects for synchronization
// validate buffer
// log start of operation
// perform operation
// log end of operation
// release lock on objects
}
}
Anti-Pattern: God Object
class Chat {
List<String> channels;
Map<String, List<Msg>> messages;
Map<String, String> accounts;
Set<String> bannedUsers;
File logFile;
File bannedWords;
URL serverAddress;
Map<String, Int> globalSettings;
Map<String, Int> userSettings;
Map<String, Graphic> smileys;
CryptStrategy encryption;
Widget sendButton, messageList;
}
class Chat {
Content content;
AccountMgr accounts;
File logFile;
ConnectionMgr conns;
}
class ChatUI {
Chat chat;
Widget sendButton, ...;
}
class AccountMgr {
... accounts, bannedUsers ...
}
Cohesion in Graph Implementations
class Graph {
Node[] nodes;
boolean[] isVisited;
}
class Algorithm {
int shortestPath(Graph g, Node n, Node m) {
for (int i; ...) {
if (!g.isVisited[i]) {
...
g.isVisited[i] = true;
}
}
return v;
}
}
- ์ด๊ฒ์ด ์ข์ ๊ตฌํ์ธ๊ฐ?
- No, graph๊ฐ data๋ฟ๋ง ์๋๋ผ ์๊ณ ๋ฆฌ์ฆ์ ์ฑ ์๊น์ง ๋งก๊ณ ์๊ธฐ ๋๋ฌธ
Bluemarble Example
- ์ด๋ ๋์์ธ์ด ๋ ๋์
cohesion์ ๊ฐ์ง๋๊ฐ?
class Player {
Board board;
/* in code somewhere... */ this.getSquare(n);
Square getSquare(String name) { // named squares
for (Square s: board.getSquares())
if (s.getName().equals(name))
return s;
return null;
}
}
class Player {
Board board;
/* in code somewhere... */ board.getSquare(n);
}
class Board {
List<Square> squares;
Square getSquare(String name) {
for (Square s: squares)
if (s.getName().equals(name))
return s;
return null;
}
}
Hints for Identifying Cohesion
- ๊ฐ๋ (concept)๋น ํ๋์ ์์ ์ฌ์ฉ
- ํด๋น concept์ ๋ชจ๋ ์ฝ๋๋ฅผ ๊ทธ ์์์ผ๋ก ๊ฐ์กฐ
โ Classes/methods๋ ์ ์ ์์ ์์์ ๊ฐ์ ธ์ผ ํจ - "Concept"์ด ๋ฌด์์ธ์ง ๋ช ํํ ์ ์๋ ์์
- Concepts๋ ๋ ์์ concepts๋ก ๋ถํ ๋ ์ ์์
- Graph with search vs.
- Basic Graph + Search Algorithm vs.
- Basic Graph + Search Framework + Concrete Search Algorithm, ๋ฑ
- ์์ง๋์ด๋ง ํ๋จ(engineering judgment) ํ์
Cohesion: Discussion
- Very Low Cohesion: Class๊ฐ ๋งค์ฐ ๋ค๋ฅธ ๊ธฐ๋ฅ ์์ญ์ ๋ง์ ๊ฒ๋ค์ ์ ์ ์ผ๋ก ์ฑ ์์ง
- Low Cohesion: Class๊ฐ ํ๋์ ๊ธฐ๋ฅ ์์ญ์์ ๋ณต์กํ ์์ ์ ์ ์ ์ผ๋ก ์ฑ ์์ง
- High Cohesion: Class๊ฐ ํ๋์ ๊ธฐ๋ฅ ์์ญ์์ ์ ๋นํ ์ฑ ์์ ๊ฐ์ง๋ฉฐ, ์์ ์ ์ํํ๊ธฐ ์ํด (๋ค๋ฅธ) classes์ ํ๋ ฅ
- High cohesion์ ์ฅ์
- Classes ์ ์ง๋ณด์ ์ฉ์ด
- ์ดํด ์ฉ์ด
- ์ข ์ข low coupling ์ง์
- ์ธ๋ถํ๋ ์ฑ ์์ผ๋ก ์ฌ์ฌ์ฉ์ฑ ์ง์
- ๊ฒฝํ ๋ฒ์น (Rule of thumb): high cohesion์ ๊ฐ์ง class๋ ์๋์ ์ผ๋ก ์ ์ ์์ ๊ณ ๋๋ก ์ฐ๊ด๋ ๊ธฐ๋ฅ์ methods๋ฅผ ๊ฐ์ง๋ฉฐ, ๋๋ฌด ๋ง์ ์์ ์ ์ํํ์ง ์์
Coupling vs Cohesion (Extreme cases)
- ๋ชจ๋ ์ฝ๋๊ฐ ํ๋์ class/method์
- Very low coupling, ๊ทธ๋ฌ๋ very low cohesion
- ๋ชจ๋ ๊ตฌ๋ฌธ(statement)์ด ๋ถ๋ฆฌ๋จ
- Very high cohesion, ๊ทธ๋ฌ๋ very high coupling
- ์ข์ tradeoff๋ฅผ ์ฐพ์ ๊ฒ; low representational gap ๋ฑ ๋ค๋ฅธ ์์น๋ค๋ ๊ณ ๋ ค
Design Heuristic: Information Expert
Information Expert (Design Heuristic)
- Heuristic: ์ฑ
์์ ์ํํ๋ ๋ฐ ํ์ํ ์ ๋ณด๋ฅผ ๊ฐ์ง class์ ์ฑ
์์ ํ ๋น
- ์ผ๋ฐ์ ์ผ๋ก ๊ณตํต์ ์ธ ์ง๊ด์ ๋ฐ๋ฆ
- Domain Model classes ๋์ Software classes
- Software classes๊ฐ ์์ง ์กด์ฌํ์ง ์๋ ๊ฒฝ์ฐ, Domain Model์์ ์ ์ ํ ์ถ์ํ(abstractions)๋ฅผ ์ฐพ์ (-> correspondence)
- Design process: Domain model์์ ๋์ถ
- ํต์ฌ ์์น: Low representational gap, low coupling
Information Expert: Example 1
- ์ด๋ class๊ฐ shipment์ ๋ฌด๊ฒ๋ฅผ ๊ณ์ฐํ๋ ๋ฐ ํ์ํ ๋ชจ๋ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋๊ฐ?
Information Expert: Example 2

- ํ๋งค(sale)์ ์ดํฉ(grand total)์ ์๋ ์ฑ ์์ ๋๊ตฌ์๊ฒ ์๋๊ฐ?
- (๋ค์ด์ด๊ทธ๋จ 71, 72 ๋ด์ฉ)
- Design Class Responsibility
- Sale: ํ๋งค ์ด์ก(sale total)์ ์
- SalesLineItem: ๋ผ์ธ ์์ดํ ์๊ณ(line item subtotal)๋ฅผ ์
- ProductSpecification: ์ ํ ๊ฐ๊ฒฉ(product price)์ ์
| Design Class | Responsibility |
|---|---|
| Sale | Knows sale total |
| SalesLineItem | Knows line item subtotal |
| ProductSpecification | Knows product price |
Information Expert โ "Do It Myself Strategy"
- Expert๋ ๋ณดํต software object๊ฐ ์์ ์ด ๋ํ๋ด๋ ๋ฌด์๋ฌผ(inanimate) ์ค์ ์ธ๊ณ ์ฌ๋ฌผ์ ๋ํด ์ผ๋ฐ์ ์ผ๋ก ์ํ๋๋ ์์
๋ค์ ์ง์ ์ํํ๋ ์ค๊ณ๋ก ์ด์ด์ง
- ํ๋งค(sale)๋ ๋น์ ์๊ฒ ์ด์ก์ ๋งํด์ฃผ์ง ์์; ๊ทธ๊ฒ์ ๋ฌด์๋ฌผ
- OO design์์, ๋ชจ๋ software objects๋ "์ด์์๊ณ " "์๋ช (animated)"์ด ์์ผ๋ฉฐ, ์ฑ ์์ ๋งก๊ณ ์ผ์ ํ ์ ์์
- ๊ทธ๋ค์ ์์ ์ด ์๋ ์ ๋ณด์ ๊ด๋ จ๋ ์ผ์ ํจ
Design Heuristic: Creator
Creator (Design Heuristic)
- Problem: ๋๊ฐ A๋ฅผ ์์ฑํ๋๊ฐ?
- Solution: ๋ค์๊ณผ ๊ฐ์ ๊ฒฝ์ฐ B์๊ฒ class A์ instance ์์ฑ ์ฑ
์ ํ ๋น
- B๊ฐ A objects๋ฅผ aggregate, B๊ฐ A objects๋ฅผ ํฌํจ, B๊ฐ A objects์ instances๋ฅผ ๊ธฐ๋ก, B๊ฐ A objects๋ฅผ ๋ฐ์ ํ๊ฒ ์ฌ์ฉ, B๊ฐ A objects ์์ฑ์ ํ์ํ ์ด๊ธฐํ data๋ฅผ ๊ฐ์ง (๋ง์์๋ก ์ข์)
- ์ ํ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, B๊ฐ A objects๋ฅผ aggregate ํ๊ฑฐ๋ ํฌํจํ๋ ๊ฒ์ ์ ํธ
- Key idea: Creator๋ ์ด์ฐจํผ ์ฐธ์กฐ(reference)๋ฅผ ์ ์งํด์ผ ํ๋ฉฐ, ์์ฑ๋ object๋ฅผ ์์ฃผ ์ฌ์ฉํ๊ฒ ๋ ๊ฒ
- Process: Domain model, interaction diagrams์์ ์ถ์ถ
- ํต์ฌ ์์น: Low coupling, low representational gap
Creator: Example
- Beetle objects ์์ฑ ์ฑ
์์ ๋๊ตฌ์๊ฒ ์๋๊ฐ?
- Creator pattern์ Tree๋ฅผ ์ ์

- Interaction diagram:

Creator (GRASP)
- Problem: ๊ฐ์ฒด ์์ฑ ์ฑ
์ ํ ๋น
- Graph์์ Nodes๋ ๋๊ฐ ์์ฑ?
- SalesItem์ instances๋ ๋๊ฐ ์์ฑ?
- Simulation์์ Children์ ๋๊ฐ ์์ฑ?
- Bluemarble ๊ฒ์์์ Tiles๋ ๋๊ฐ ์์ฑ?
- AI? Player? Main class? Board? Meeple (Dog)?
Creator: Discussion of Design Goals/Principles
- Low coupling, high cohesion ์ฆ์ง
- Class๊ฐ ์ฐธ์กฐํด์ผ ํ objects ์์ฑ ์ฑ ์
- Objects๋ฅผ ์ง์ ์์ฑํ๋ฉด, object ์์ฑ์ ์ํด ๋ค๋ฅธ class์ ์์กดํ๋ ๊ฒ์ ํผํจ
- Evolvability (design for change) ์ฆ์ง
- Object ์์ฑ์ด ์จ๊ฒจ์ ธ(hidden), ๋ก์ปฌ์์ ๊ต์ฒด ๊ฐ๋ฅ
- Contra (๋ฐ๋): ๋๋๋ก objects๋ ํน๋ณํ ๋ฐฉ์์ผ๋ก ์์ฑ๋์ด์ผ ํจ
- ๋ณต์กํ ์ด๊ธฐํ
- ๋ค๋ฅธ ์ํฉ์์ ๋ค๋ฅธ classes๋ฅผ instantiate
- ์ด ๊ฒฝ์ฐ, cohesion์ ์์ฑ์ ๋ค๋ฅธ object์ ๋๋๋ก ์ ์: builder, factory method ๊ฐ์ design patterns ์ฐธ๊ณ
Other Design Heuristics
- (ํฅํ ๊ฐ์):
- Mutability ์ต์ํ
- Conceptual weight ์ต์ํ
- ์์(Inheritance)๋ณด๋ค composition/delegation ์ ํธ
- Coupling์ ์ค์ด๊ธฐ ์ํด indirection ์ฌ์ฉ
- ...
Object-level Artifacts of This Design Process
- Object interaction diagrams๋ objects์ methods๋ฅผ ์ถ๊ฐ
- ์ถ๊ฐ์ ์ธ data ์ฑ ์ ์ถ๋ก ๊ฐ๋ฅ
- ์ถ๊ฐ์ ์ธ data types ๋ฐ architectural patterns ์ถ๋ก ๊ฐ๋ฅ
- Object model์ ์ค์ํ ์ค๊ณ ๊ฒฐ์ (design decisions)์ ์ข
ํฉ(aggregates)
- ๊ตฌํ ๊ฐ์ด๋(implementation guide) ์ญํ
Summary
- Design์ ํ์ง ์์ฑ(quality attributes)์ ์ํด ์ฃผ๋๋จ
- Evolvability, separate development, reuse, performance, ...
- Design principles๋ ํ์ง ๋ฌ์ฑ์ ์ํ ์ง์นจ ์ ๊ณต
- Low coupling, high cohesion, high correspondence, ...
- GRASP design heuristics๋ ์ด๋ฌํ ์์น๋ค์ ์ฆ์ง
- Creator, Expert, Controller, ...
