UML 시퀀스 다이어그램
•
시퀀스 다이어그램은 객체들의 상호작용을 보여줄 때 사용하는 다이어그램입니다.
•
시퀀스 다이어그램에서는 main 함수와 객체의 생명선lifeline이 입니다.
•
생명선들이 오가면서 객체 인스턴스화와 맴버함수 호출을 표현합니다.
클래스, 객체, 인스턴스의 개념
•
클래스(Class) 란
◦
객체를 만들어 내기 위한 설계도 혹은 틀
◦
2연관되어 있는 변수와 메서드의 집합
•
객체(Object) 란
◦
소프트웨어 세계에 구현할 대상
◦
클래스에 선언된 모양 그대로 생성된 실체
◦
특징
◦
‘클래스의 인스턴스(instance)’ 라고도 부른다.
◦
객체는 모든 인스턴스를 대표하는 포괄적인 의미를 갖는다.
◦
oop의 관점에서 클래스의 타입으로 선언되었을 때 ‘객체’라고 부른다.
•
인스턴스(Instance) 란
◦
설계도를 바탕으로 소프트웨어 세계에 구현된 구체적인 실체
◦
즉, 객체를 소프트웨어에 실체화 하면 그것을 ‘인스턴스’라고 부른다.
◦
실체화된 인스턴스는 메모리에 할당된다.
◦
특징
◦
인스턴스는 객체에 포함된다고 볼 수 있다.
◦
oop의 관점에서 객체가 메모리에 할당되어 실제 사용될 때 ‘인스턴스’라고 부른다.
◦
추상적인 개념(또는 명세)과 구체적인 객체 사이의 관계 에 초점을 맞출 경우에 사용한다.
◦
‘~의 인스턴스’ 의 형태로 사용된다.
◦
객체는 클래스의 인스턴스다.
◦
객체 간의 링크는 클래스 간의 연관 관계의 인스턴스다.
◦
실행 프로세스는 프로그램의 인스턴스다.
애플스토어 청구서 작성 프로그램의 시퀀스 다이어그램
•
main 함수에서 product(코드에서는 applemachine이라고 선언 하였습니다.)
•
main 함수에서 product객체 2개와 invoice 객체 1개를 인스턴스화 하고 있다.
•
main 함수는 Invoice 클래스의 add 함수를 호출해서 Product 객체를 청구서에 추가한다.
•
마지막으로 Invoice.add 맴버함수에서 Product getPrice함수를 호출해서 가격을 가져온다.
다이어그램
소스코드
/AppleMachine.hpp
//
// AppleMachine.hpp
// AppleStore
//
// Created by Glory on 2021/04/04.
//
#ifndef AppleMachine_hpp
#define AppleMachine_hpp
/* AppleMachine_hpp */
//AppleMachine 클래스의 인터페이스 파일
#include <string>
#include <iostream>
using namespace std;
class AppleMachine
{
private:
string name;
double unitPrice;
public:
AppleMachine(string name, double unitPrice);
~AppleMachine();
double getPrice() const;
};
#endif
C++
복사
/AppleMachine.cpp
//
// AppleMachine.cpp
// AppleStore
//
// Created by Glory on 2021/04/04.
//
#include "AppleMachine.hpp"
//AppleMachine 클래스의 구현 파일
// 생성자
AppleMachine::AppleMachine(string nm, double up)
: name(nm), unitPrice(up)
{
}
// 소멸자
AppleMachine::~AppleMachine()
{
}
// getPrice 멤버 함수
double AppleMachine::getPrice() const
{
return unitPrice;
}
C++
복사
/TotalPrice.hpp
//
// TotalPrice.hpp
// AppleStore
//
// Created by Glory on 2021/04/04.
//
#ifndef TotalPrice_hpp
#define TotalPrice_hpp
//TotalPrice 클래스의 인터페이스 파일
#include "AppleMachine.hpp"
class TotalPrice
{
private:
int invoiceNumber;
double invoiceTotal;
public:
TotalPrice(int invoiceNumber);
~TotalPrice();
void add(int quantity, AppleMachine applemachine);
void print() const;
};
#endif
C++
복사
/TotalPrice.cpp
//
// TotalPrice.cpp
// AppleStore
//
// Created by Glory on 2021/04/04.
//
#include "TotalPrice.hpp"
//TotalPrice 클래스의 구현 파일
// 생성자
TotalPrice::TotalPrice(int invNum)
: invoiceNumber(invNum), invoiceTotal(0.0)
{
}
// 소멸자
TotalPrice::~TotalPrice()
{
}
// add 멤버 함수
void TotalPrice::add(int quantity, AppleMachine applemachine)
{
invoiceTotal += quantity * applemachine.getPrice();
}
// print 멤버 함수
void TotalPrice::print() const
{
cout << "청구 번호: " << invoiceNumber << endl;
cout << "총액: " << invoiceTotal << endl;
}
C++
복사
/main.cpp
//
// main.cpp
// AppleStore
//
// Created by Glory on 2021/04/04.
//
//TotalPrice 클래스를 사용하는 애플리케이션 파일
#include "TotalPrice.hpp"
int main()
{
// Applemachine 객체 인스턴스화
AppleMachine applemachine1("iMac", 100.00);
AppleMachine applemachine2("iPad", 10.00);
AppleMachine applemachine3("iPhone", 1.00);
// TotalPrice 객체를 인스턴스화하고 Applemachine 객체를 사용해 출력
TotalPrice invoice(1042);
invoice.add(1, applemachine1);
invoice.add(6, applemachine2);
invoice.add(3, applemachine3);
invoice.print();
return 0;
}
C++
복사
<과제>
•
위의 코드를 보면 machine 대신에 applemachine이라고 말을 바꿨는데, 코드보면 객체를 인스턴스화를 3개를 했습니다. 그 3개의 객체를 인스턴스화 하는 시퀀스 다이어그램을 그리시면 됩니다.
•
그리고 뒤에 시퀀스 다이어그램 예제가 2개가 더 있는데 그것도 그리시면됩니다. 제출은 xml 파일과 png 파일로 두개를 받겠습니다.
•
xml 파일로 다운로드 받는 방법
•
이렇게 학번_이름 작성하시고 디바이스에 저장하시면 됩니다.
•
이렇게 저장하시면 됩니다, (이름이랑 학번을 잘못 입력해서 캡처했습니다. 학번_이름 이렇게 해주세요.)