λ°μν
What is UML?
UML(Unified Modeling Language, ν΅ν© λͺ¨λΈλ§ μΈμ΄)λ μμ€ν μ ꡬ쑰μ λμμ μκ°ννκ³ , μ¬μ(specification)μ λ¬Έμννλ λ° μ¬μ©λλ νμ€νλ λͺ¨λΈλ§ μΈμ΄μ λλ€.
- μμ€ν μ μκ°ν νκ±°λ μμ€ν μ μ¬μ, μ€κ³λ₯Ό λ¬Έμν νκΈ° μν νν λ°©λ²μ λλ€.
- ν΅ν© λͺ¨λΈλ§ μΈμ΄λ κ°μ²΄ μ§ν₯ νλ‘κ·Έλλ° μννΈμ¨μ΄ μ§μ μμ€ν μ κ°λ°ν λ μ°μΆλ¬Όμ λͺ μΈν, μκ°ν, λ¬Έμνν λ μ¬μ©ν©λλ€.
- μΌλ°μ μΌλ‘ UMLμ λ²μλ λ§€μ° λμ§λ§, μ¬κΈ°μλ ν΄λμ€ λ€μ΄μ΄κ·Έλ¨ λ° μνμ€ λ€μ΄μ΄κ·Έλ¨μ λν΄μλ§ μ€λͺ ν΄ λ³΄κ² μ΅λλ€.
- Code Patternλ€μ ννν λλ μ μ©ν©λλ€.
Class Diagram: ν΄λμ€μ κ³μΈ΅ κ΄κ³
ν΄λμ€ λ€μ΄μ΄κ·Έλ¨μ μμ€ν μ μ μ ꡬ쑰λ₯Ό λνλ΄λ UML ꡬ쑰 λ€μ΄μ΄κ·Έλ¨ μ€ νλμ λλ€
μ΄ λ€μ΄μ΄κ·Έλ¨μ μμ€ν μ ꡬμ±νλ ν΄λμ€λ€ μ¬μ΄μ κ΄κ³λ₯Ό 보μ¬μ€λλ€
- κ° ν΄λμ€λ μμ±(attributes)κ³Ό λ©μλ(methods)λ₯Ό κ°μ§λ©°, ν΄λμ€ κ°μλ μμ, μ°κ΄, μ§ν©, μμ‘΄ λ± λ€μν κ΄κ³κ° μμ μ μμ΅λλ€.
from abc import *
class ParentClass(metaclass=ABCMeta):
field1 = 0
field2 = 0
@abstractmethod
def methodA(self):
pass
def methodB(self):
pass
class ChildClass(ParentClass):
def methodA(self):
print("methodA is implemented", field1)
def methodB(self):
print("methodC is defined")
- abstract ν΄λμ€, Methodλ±μ μ΄ν€λ¦μ²΄λ‘ ννλ©λλ€.
- ν΄λμ€κ° νμ΄νμ λ°©ν₯μ νμν΄λμ€μμ μμν΄λμ€λ‘ μ°κ²°λ©λλ€.
Class Diagram: ꡬν κ΄κ³
from abc import *
class Printable(metaclass=ABCMeta):
@abstractmethod
def show(self):
pass
@abstractmethod
def newpage(self):
pass
class PrintClass(Printable):
def show(self):
print("show implemented")
def newPage(self):
print("newPage implemented")
pc = PrintClass
pc.show()
Class Diagram: μ§μ½(aggregation)
class Color():
def __init__(self):
self.r = 0
self.g = 0
self.b = 0
class Fruit():
def __init__(self):
self.color = Color()
class Basket():
def __init__(self):
self.fruits = []
for i in range(10):
self.fruits.append(Fruit())
Classμ κ΄κ³
- ν΄λμ€μ κ΄κ³λ₯Ό λνλ΄κΈ° μν΄ κ΄λ ¨λ μ΄λ¦μ > νμλ₯Ό λΆμ¬μ€λλ€.
- μ΄ κ²½μ°λ Clientκ° Targetμ Use(μ¬μ©)ν©λλ€.
- μ΄ κ²½μ°λ Factoryκ° Productλ₯Ό Create(μμ±)ν©λλ€.
- Subjectκ° Observerμκ² Notifies(ν΅μ§)ν©λλ€.
Sequence Diagram (μνμ€ λ€μ΄μ΄κ·Έλ¨)
μνμ€ λ€μ΄μ΄κ·Έλ¨μ UMLμ μνΈμμ© λ€μ΄μ΄κ·Έλ¨ μ€ νλλ‘, κ°μ²΄ κ°μ μνΈμμ©κ³Ό μ΄λ¬ν μνΈμμ©μ΄ μκ° μμμ λ°λΌ μ΄λ»κ² λ°μνλμ§λ₯Ό λνλ λλ€.
- μνμ€ λ€μ΄μ΄κ·Έλ¨(Sequence Diagram)μ νλ‘κ·Έλ¨μ΄ μλν λ μ΄λ€ λ©μλκ° μ΄λ€ μμλ‘ μ€νλλκ°, μ΄λ€ μΆμ ν΄λμ€κ° μ΄λ€ μμλ‘ μ€νλλκ°λ₯Ό ννν©λλ€.
- ν΄λμ€ λ€μ΄μ΄κ·Έλ¨μ ‘μκ°μ μν΄ λ³νμ§ μλκ² (μ μ )’μ λνλ΄λ©°, μνμ€ λ€μ΄μ΄κ·Έλ¨μ ‘μκ°μ λ°λΌ λ³νλκ²(λμ )’ μ λνλ λλ€.
- → λ©μλ νΈμΆ, ← λ©μλ λ°ν
class Device():
def write(self):
print("write")
class Server():
def _init_(self):
self.device = Device()
def open(self):
pass
def print(self):
self.device.write()
def close(self):
pass
class Client():
def _init_(self):
self.server = Server()
def operation(self):
self.server.open()
self.server.print()
self.server.close()
c = Client()
c.work()
λ°μν
'πΊοΈ Design Pattern' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Design Pattern] Factory Method Pattern - ν©ν 리 λ©μλ ν¨ν΄ (0) | 2024.04.08 |
---|---|
[Design Pattern] Factory Pattern - ν©ν 리 ν¨ν΄ (0) | 2024.04.08 |
[Design Pattern] Object-Oriented Programming (OOP) (0) | 2024.03.28 |
[Design Pattern] Solid Principles (μ리λ μμΉ) (0) | 2024.03.28 |
[Design Pattern] Design Pattern (0) | 2024.03.21 |