• Mindscape ๐Ÿ”ฅ
    • Playlist ๐ŸŽง
  • ๐Ÿค– Artifical Intelligence

    • 1. Basics; Linear Algebra
    • 2. Basics; Linear Algebra (2), Search (1)
    • 3. Search (2)
    • 4. Knowledge and Logic (1)
    • 5. Knowledge and Logic (2)
    • 6. Probability
    • 7. Information Theory
    • 8. Probabilitc Reasoning (2)
    • 9. Probabilitc Reasoning (3)
    • 10. Machine Learning (1)
    • 11. Machine Learning (2)
    • 12. Machine Learning (3)
    • 13. Linear Models
    • 14. Other Classic ML Models (1)
    • 15. Other Classic ML Models (2)
  • ๐Ÿ”’ Computer Security

    • 01. Overview
    • 02. ์ •๋ณด๋ณด์•ˆ์ •์ฑ… ๋ฐ ๋ฒ•๊ทœ
    • 03. Cryptographic Tools
    • 04. User Authentication
    • 05. Access Control
    • 06. Database Security
    • 07. Malicious Software
    • 08. Firmware Analysis
  • ๐Ÿ—„๏ธ Database System

    • 1. Introduction
    • 2. Relational Model
    • 3. SQL
    • 6. E-R Model
    • 7. Relational Database Design (1)
    • 7. Relational Database Design (2)
    • 13. Data Storage Structures
    • 14. Indexing
    • 15. Query Processing
  • ๐Ÿ“ Software Engineering

    • 2. Introduction to Software Engineering
    • 3. Process
    • 4. Process Models
    • 5. Agile
    • 6. Requirements
    • 7. Requirements Elicitation and Documentation
    • 8. Architecture
    • 9. Unified Modelling Language
    • 10. Object-Oriented Analysis
    • Object-Oriented Design
  • ๐Ÿง  Algorithm

    • Python ์‹œ๊ฐ„ ์ดˆ๊ณผ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ํŒ
    • C++ std::vector ์‚ฌ์šฉ๋ฒ• ์ •๋ฆฌ
    • Vim ์‚ฌ์šฉ ๋งค๋‰ด์–ผ
    • 1018๋ฒˆ: ์ฒด์ŠคํŒ ๋‹ค์‹œ ์น ํ•˜๊ธฐ
    • 1966๋ฒˆ: ํ”„๋ฆฐํ„ฐ ํ

Object-Oriented Design

From Requirements to Code

  • ์‚ฌ์šฉ์ž ์š”๊ตฌ์‚ฌํ•ญ (Requirements)
  • ๊ธฐ์ ? Code

From Problem to Solution

  • Problem Space (Domain Model)
    • ์‹ค์ œ ์„ธ๊ณ„์˜ ๊ฐœ๋…
    • ์š”๊ตฌ์‚ฌํ•ญ, ๊ฐœ๋…
    • ๊ฐœ๋… ๊ฐ„์˜ ๊ด€๊ณ„
    • ๋ฌธ์ œ ํ•ด๊ฒฐ
    • ์–ดํœ˜ ๊ตฌ์ถ•
  • Solution Space (Object Model)
    • ์‹œ์Šคํ…œ ๊ตฌํ˜„
    • Classes, objects
    • Objects ๊ฐ„์˜ ์ฐธ์กฐ ๋ฐ ์ƒ์† ๊ณ„์ธต
    • ๊ฒฐ๊ณผ ๊ณ„์‚ฐ
    • ํ•ด๊ฒฐ์ฑ… ์ฐพ๊ธฐ

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

alt text

From Concepts to Objects

  • Domain ๊ฐœ๋…์€ classes์™€ ์–ด๋–ป๊ฒŒ ๋‹ค๋ฅธ๊ฐ€?
    • ๋ชจ๋“  ๊ฐœ๋…์ด class๊ฐ€ ๋˜์–ด์•ผ ํ•˜๋Š”๊ฐ€?
    • ๋ชจ๋“  class๊ฐ€ ๊ฐœ๋…์„ ๋‚˜ํƒ€๋‚ด์•ผ ํ•˜๋Š”๊ฐ€?

Object Diagrams

  • Fields์™€ methods๋ฅผ ๊ฐ€์ง„ Objects/classes
  • Methods๋ฅผ ๊ฐ€์ง„ Interfaces
  • Associations, visibility, types alt text

Object Diagram Notation: Classes/Objects

alt text

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

Object Diagram Notation: Interfaces

alt text

interface LibraryAccount {
  boolean borrow(Book b);
  void returnItem(Book b);
  void payFees(int payment);
}

Object Diagram Notation: Associations

alt text

class LibraryAccount {
  ...
  List<Book> borrowedBooks;
}
class Book {
  ...
  LibraryAccount borrowedBy;
}
  • Fields๋ฅผ associations ๋Œ€์‹  ๋˜๋Š” ์ถ”๊ฐ€๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋ง ๊ฒƒ
  • Fields๋Š” ๊ธฐ๋ณธ types์—๋งŒ ์‚ฌ์šฉ

alt text

Class Diagram vs Object Diagram

  • Classes์™€ objects ๋‘˜ ๋‹ค modeling ๊ฐ€๋Šฅ
  • ์šฉ์–ด๋Š” ์ข…์ข… ํ˜ผ์šฉ๋จ
  • ํŠน์ • objects๋ฅผ modelingํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ objectId: Class ํ‘œ๊ธฐ๋ฒ• ์‚ฌ์šฉ alt text

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

alt text

Domain Model vs Object Model

alt text

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: ๋„์„œ๊ด€ ํšŒ์›์ด ๋„์„œ๊ด€ ์นด๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋„์„œ๊ด€ ์‹œ์Šคํ…œ ํ‚ค์˜ค์Šคํฌ์—์„œ ๋กœ๊ทธ์ธํ•˜๊ณ  ์ฑ…์„ ๋Œ€์ถœ
  • ํšŒ์›์ด ๋ฏธ๋‚ฉ ์—ฐ์ฒด๋ฃŒ๊ฐ€ ์—†๋Š”์ง€ ํ™•์ธํ•œ ํ›„, ๋„์„œ๊ด€ ์‹œ์Šคํ…œ์€ ํ˜„์žฌ ๋‚ ์งœ์— ๋Œ€์—ฌ ๊ธฐ๊ฐ„์„ ๋”ํ•ด ์ฑ…์˜ ๋ฐ˜๋‚ฉ ๊ธฐํ•œ์„ ๊ฒฐ์ •
  • ํ•ด๋‹น ์ฑ…๊ณผ ๋ฐ˜๋‚ฉ ๊ธฐํ•œ์„ ํšŒ์›์˜ ๋„์„œ๊ด€ ๊ณ„์ •์— ๋Œ€์ถœ ํ•ญ๋ชฉ์œผ๋กœ ๊ธฐ๋ก alt text

Interaction Diagrams

  • Objects ๊ฐ„์˜ ์ƒํ˜ธ์ž‘์šฉ
  • ๋‘ ๊ฐ€์ง€ ์ผ๋ฐ˜์ ์ธ ํ‘œ๊ธฐ๋ฒ•: sequence diagrams, communication diagrams
  • Sequence diagrams๋Š” system sequence diagrams์™€ ์œ ์‚ฌํ•˜์ง€๋งŒ, objects/classes ๊ฐ„์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ๋ฌ˜์‚ฌ alt text

Example

alt text

Interaction Diagram Practice

  • Use case scenario: ...์ฑ…์„ ๋Œ€์ถœ. ํšŒ์›์˜ ๋ฏธ๋‚ฉ ์—ฐ์ฒด๋ฃŒ๊ฐ€ ์—†๋Š”์ง€ ํ™•์ธ ํ›„, ์‹œ์Šคํ…œ์€ ๋Œ€์ถœ ๊ธฐ๊ฐ„(loan period)์„ ํ˜„์žฌ ๋‚ ์งœ์— ๋”ํ•ด ๋ฐ˜๋‚ฉ ๊ธฐํ•œ์„ ๊ฒฐ์ •ํ•˜๊ณ , ์ฑ…๊ณผ ๋ฐ˜๋‚ฉ ๊ธฐํ•œ์„ ํšŒ์› ๊ณ„์ •์— ๋Œ€์ถœ ํ•ญ๋ชฉ์œผ๋กœ ๊ธฐ๋ก alt text

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๊ฐœ ํŒจํ„ด

  1. Information expert
  2. Creator
  3. Controller
  4. Indirection
  5. Low coupling
  6. High cohesion
  7. Polymorphism
  8. Protected variations
  9. Pure fabrication

Information Expert

NameInformation Expert
Problem๊ฐ์ฒด์— ์ฑ…์ž„์„ ํ• ๋‹นํ•˜๋Š” ๊ธฐ๋ณธ ์›์น™์€ ๋ฌด์—‡์ธ๊ฐ€?
Solution์ฑ…์ž„์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง„ class์— ์ฑ…์ž„์„ ํ• ๋‹น

Applying Information Expert

  • Software Board๋Š” ๋ชจ๋“  Square objects๋ฅผ ์ง‘ํ•ฉ(aggregate)์‹œํ‚ฌ ๊ฒƒ
  • ๋”ฐ๋ผ์„œ, Board๋Š” ์ด ์ฑ…์ž„์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง alt text

Creator

NameCreator
Problem๋ˆ„๊ฐ€ A๋ฅผ ์ƒ์„ฑํ•˜๋Š”๊ฐ€?
Solution๋‹ค์Œ ์ค‘ ํ•˜๋‚˜ ์ด์ƒ์ด ์ฐธ(๋งŽ์„์ˆ˜๋ก ์ข‹์Œ)์ผ ๊ฒฝ์šฐ, class B์— class A์˜ instance ์ƒ์„ฑ ์ฑ…์ž„์„ ํ• ๋‹น
B๊ฐ€ A๋ฅผ "ํฌํ•จ"ํ•˜๊ฑฐ๋‚˜ ๋ณตํ•ฉ์ ์œผ๋กœ aggregate ํ•จ
B๊ฐ€ A๋ฅผ ๊ธฐ๋กํ•จ
B๊ฐ€ A๋ฅผ ๊ธด๋ฐ€ํ•˜๊ฒŒ ์‚ฌ์šฉํ•จ
B๊ฐ€ A ์ƒ์„ฑ์„ ์œ„ํ•œ ์ดˆ๊ธฐํ™” data๋ฅผ ๊ฐ€์ง

Example: Creator

alt text

  • Dynamic model์—์„œ Creator pattern ์ ์šฉ
  • Design Model์˜ DCD์—์„œ, Board๋Š” Squares์™€ composite aggregation association์„ ๊ฐ€์ง
    • Static model์— Creator ์ ์šฉ ์ค‘

Controller

NameController
ProblemUI layer๋ฅผ ๋„˜์–ด system operation์„ ์ˆ˜์‹ ํ•˜๊ณ  ์กฐ์ •("์ œ์–ด")ํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ๊ฐ์ฒด๋Š” ๋ฌด์—‡์ธ๊ฐ€?
Solution๋‹ค์Œ ์„ ํƒ์ง€ ์ค‘ ํ•˜๋‚˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด์— ์ฑ…์ž„ ํ• ๋‹น
์ „์ฒด "system", "root object", software๊ฐ€ ์‹คํ–‰ ์ค‘์ธ device ๋˜๋Š” ์ฃผ์š” subsystem (๋ชจ๋‘ facade controller์˜ ๋ณ€ํ˜•)
System operation์ด ๋ฐœ์ƒํ•˜๋Š” use case scenario (use case ๋˜๋Š” session controller)

alt text

  • 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

alt text

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

alt text

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 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

alt text

  • ํŒ๋งค(sale)์˜ ์ดํ•ฉ(grand total)์„ ์•„๋Š” ์ฑ…์ž„์€ ๋ˆ„๊ตฌ์—๊ฒŒ ์žˆ๋Š”๊ฐ€?
  • (๋‹ค์ด์–ด๊ทธ๋žจ 71, 72 ๋‚ด์šฉ)
  • Design Class Responsibility
    • Sale: ํŒ๋งค ์ด์•ก(sale total)์„ ์•Ž
    • SalesLineItem: ๋ผ์ธ ์•„์ดํ…œ ์†Œ๊ณ„(line item subtotal)๋ฅผ ์•Ž
    • ProductSpecification: ์ œํ’ˆ ๊ฐ€๊ฒฉ(product price)์„ ์•Ž
Design ClassResponsibility
SaleKnows sale total
SalesLineItemKnows line item subtotal
ProductSpecificationKnows 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๋ฅผ ์ œ์•ˆ

alt text

  • Interaction diagram:

alt text

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, ...
์ตœ๊ทผ ์ˆ˜์ •: 25. 11. 6. ์˜คํ›„ 12:07
Contributors: kmbzn
Prev
10. Object-Oriented Analysis

BUILT WITH

CloudflareNode.jsGitHubGitVue.jsJavaScriptVSCodenpm

All trademarks and logos are property of their respective owners.
ยฉ 2025 kmbzn ยท MIT License