Algorithm Study

데이터 구조 및 분석 : UML notation & Structure and Relationship

sara2601 2022. 12. 4. 09:29

본 게시글은 Edwith 문일철 교수님의 데이터 구조 및 분석: Linear Structure and Dynamic Programming을 듣고 정리한 내용입니다.

More About UML Notations : 

  • class를 어떻게 하면 잘 설계할 수 있을까?
  • 현실에서는 다양한 UML diagram들이 있다. use-case, class, state, deployment diagram 등이 존재. 
  • OOP (Object-Oriented Programming) 이외에도 다양한 설계 문서들이 있다!

UML Notation

Person : Abstract Class(속에 abstract method가 존재.)
-> Customer(instantiation) : 위 Person을 상속받아, method를 override해서 사용됨.
-> Named Instance(Park) : Customer class를 활용한 instance
Member Variable, Methods는 위와 같이 정의됨. 
Visibility Option: encapsulation에 도움됨. 
login() : method signature. 이것이 동일할 경우 method override가 가능하다. 즉, 자식 class의 method가 대표가 됨. 
method signature가 similar일 경우(not same) : method overload.

Structure of Classes in Class Diagram 

  • 여러 class들을 묶어서 사용하기 때문에 설계도처럼 볼 수 있음. 
  •  

8개 class가 어떤 관계를 상호 가지고 있는가를 설계도에서 명시함. 
직선 연결 : association. 이를 활용해 Customer와 Order 간 관계 명시 
generalization : Credit은 Payment의 subclass이며 Credit은 Payment를 inherit한다. (Cash, Check도 마찬가지)
값을 내는데 3개의 다른 방법이 있다는 의미. 공통적인 속성 amount는 Payment class에서 받아옴.
Credit - credit card number, 각각의 attribute는 따로 존재
hollow point arrow (generalization), 직선 (association), 마름모꼴 화살표(aggregation)
이제 어떻게 이런 화살표 관계를 읽어낼 수 있는지 살펴볼 예정임.

Generalization (--▷) 

  • inheritance relationship에 기반을 둠. -> superclass, subclass가 존재.
  • is-a relationship  (Customer is a Person - Customer는 Person의 한 종류.)
  • Customer → Person ( from subclass → to superclass) 
  • 선언하지 않아도 Person의 NatlRegisterNum attribute는 이미 Customer와 Employee에 존재하며, login() method 역시 둘 모두에 존재.

 

- Base class : Person

- Leaf Class : 
  * Park, Koh, John, Kim 

 

 

Association (-- simple line or →)

  •  has-a relationship (어떤 class가 무엇을 가지고 있다) 
  • Member Variables( attribute of property )
  • 기본적으로 simple line, 그런데 한쪽 방향 화살표가 있는 경우 : 
    - → : 하나의 customer가 여러 BankAccount에 reference를 가지고 있다는 방향성을 의미.
    - __ : simple line - 양쪽으로 모두 연관되어있음. 
    즉, 화살표는 Navigability. 
  • 아래 코드를 살펴보면, customer class는 lstAccounts = []를 보유. 여러 account를 저장할 예정. 따라서 여러 account를 가질 수 있는 것이 Customer가 되겠다. 반면, BankAccount class의 경우 AccountHolder는 하나의 customer 정보만 보유. 
    - 한 Customer가 여러 개의 (1 : many) account를 가지고 있다. 
    - 한 Account가 하나의 Holder customer(1 : 1)를 가질 수 있다. 
  • 따라서 has-a relationship은 multiplicity 정보를 필요로 한다. (얼만큼 복수개를 가지고 있는가) 
    Customer 하나에 Bank Account 여러개가 가능, 반대로 BankAccount 1개는 Customer 1개에 연결
class Customer:
	ID = "No One"
    lstAccounts = []
    def addBankAccount(self, account):
    	self.lstAccount.append(account)

class BankAccount:
	strAccountHolder = "No One"
    def changeAccountHolder(self, holder):
    	self.strAccountHolder = holder

Multiplicity of Association 

  • * : many를 의미. 
  • 1 ... * : one to Many (하나 or 여러개 가능, 무조건 상대방 class에서 이 class로 적어도 1개 이상을 가지고 있어야 함 ) 
  • * or 0 ... * : 0 to Many (하나도 없거나 여러개 가능)
    ex) Customer : 맨 처음 customer 선언 시 lstAccount = [ ] 하나도 없을 수 있음.
  • 1 : 정확히 1개. 계좌 holder가 여러명이 될수도 있지만 무조건 1명만 가능하다로 정의. 
  • 0 ... 1 : One to Zero. 하나도 없거나 혹은 한명이 있을수 있다. 

Aggregation(--)

  • Special Case of Association
  • Special has-a relationship
  • 보다 더, part-whole or part-of relationship 관계라고 부르기도 함. 
  • A family member is a part of a family.