제목

Similar documents
제목

제목

제목

제목

UML

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

OOP 소개

JAVA PROGRAMMING 실습 08.다형성

01-OOPConcepts(2).PDF

gnu-lee-oop-kor-lec06-3-chap7

PowerPoint Presentation

Design Issues

소프트웨어개발방법론

PowerPoint Presentation

PowerPoint Template

Microsoft PowerPoint - CSharp-10-예외처리

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

PowerPoint 프레젠테이션

Microsoft PowerPoint - 2강

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

C++ Programming

제11장 프로세스와 쓰레드

1

Microsoft PowerPoint - additional08.ppt [호환 모드]

PowerPoint 프레젠테이션

슬라이드 1

PowerPoint 프레젠테이션

PowerPoint Presentation

C# Programming Guide - Types

Microsoft PowerPoint - additional07.ppt [호환 모드]

Inclusion Polymorphism과 UML 클래스 다이어그램 구조에 의거한 디자인패턴 해석

5장.key

PowerPoint Presentation

13 Who am I? R&D, Product Development Manager / Smart Worker Visualization SW SW KAIST Software Engineering Computer Engineering 3

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout << " 양수입력 : "; cin >> *p; if (*p <= 0) cout << " 양수를입력해야합니다 " << endl; return; 동적할

Microsoft PowerPoint - 04-UDP Programming.ppt

C++ Programming

PowerPoint Template

chap10.PDF

제 1 강 희망의 땅, 알고리즘

(Microsoft Word - \301\337\260\243\260\355\273\347.docx)

No Slide Title

PowerPoint Presentation

쉽게 풀어쓴 C 프로그래밍

유니티 변수-함수.key

PowerPoint Template

소프트웨어공학 Tutorial #2: StarUML Eun Man Choi

PowerPoint 프레젠테이션

쉽게 풀어쓴 C 프로그래밍

untitled

09-interface.key

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

C++ Programming

슬라이드 1

PowerPoint Presentation

17장 클래스와 메소드

Spring Boot/JDBC JdbcTemplate/CRUD 예제

05-class.key

DocsPin_Korean.pages

PowerPoint Presentation

Microsoft PowerPoint - 09-Object Oriented Programming-3.pptx

Slide 1

PowerPoint 프레젠테이션

윈도우시스템프로그래밍

Microsoft PowerPoint 장강의노트.ppt

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

thesis

Cluster management software

06.AnalysisModeling.key

Microsoft PowerPoint - Chapter 6.ppt

쉽게 풀어쓴 C 프로그래밍

Microsoft PowerPoint - java2 [호환 모드]

ETL_project_best_practice1.ppt

Microsoft PowerPoint - chap11

Something that can be seen, touched or otherwise sensed

어댑터뷰

자바 프로그래밍

자바GUI실전프로그래밍2_장대원.PDF

오버라이딩 (Overriding)

OOP 소개

CONTENTS SUMMARY PART 1 MARKET MARKET STRATEGY MARKET ISSUE MARKET ISSUE PART 2 CREDIT CREDIT ISSUE CREDIT ISSUE CREDIT ISSUE CREDIT ISSUE CREDIT STRA

슬라이드 1

PowerPoint 프레젠테이션

K&R2 Reference Manual 번역본

Network Programming

MVVM 패턴의 이해

JAVA PROGRAMMING 실습 02. 표준 입출력

Microsoft PowerPoint - 06_ClassDiagram(2010).ppt [호환 모드]

11강-힙정렬.ppt

JUNIT 실습및발표

PowerPoint Presentation

ecorp-프로젝트제안서작성실무(양식3)

03.Agile.key

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

Microsoft PowerPoint - Lect04.pptx

설계란 무엇인가?

A Tour of Java V

PowerPoint Presentation

rmi_박준용_final.PDF

PowerPoint Presentation

Transcription:

Object-Oriented Design Agile for Software Development 소 속 : 미래로시스템 작 성 자 : 고형호 메 일 : hhko@korea.ac.kr 홈페이지 : 1

2 Goal Object-Oriented Design

Contents Part 1. Object-Oriented Oriented Modeling 1. Object-Oriented 2. What is an Object 3. Modeling Part 2. UML 기초 1. Usecase Diagram 2. Class Diagram 3. Sequence Diagram 3 Part 3. UML 실전 1. The Fragile-Base-Class Problem 2. Customer Requirement 3. Object-Oriented Design 4. Design Pattern in Practice 5. Summary

4 Part 1. Object-Oriented Modeling

5 1. Object-Oriented

Object-Oriented 신제품실패원인 (IBM, 1996)? 6 출처 : "DMAIC" 발표자료인용 (2005.04.06 삼성경제연구소 6 시그마실김종만 )

Object-Oriented Object-Oriented 의장점 1. 데이터지향적이다. DATA FUNCTION ( 변경횟수 ) 2. 인터페이스지향적이다. Creation : Use = ( 객체사용횟수 ) 1 : N 3. Real World 지향적이다. Read World : Mapping 1 : 1 7

Object-Oriented Object-Oriented 의특징 1. 캡슐화 (Encapsulation) 캡슐화 (Encapsulation) : 데이터와연산을한데묶는것 은닉 (Hiding) : 내부데이터, 내부연산을외부에서접근하지못하도록격리시키는것 2. 상속 (Inheritance) 코드재사용다형성은닉 구현 (Implement) 상속 인터페이스 (Interface) 상속 O O 구현상속을통한재사용 -. 구현상속을통한재사용은불필요한결합도를증가시킨다. 재사용을위해서는 Composition 을사용하자. -. 구현상속은여러클래스가공통의연산집합을공유하고있을때정규화를위해사용하자. 구현상속을통한다형성 -. 깨지기쉬운기반클래스문제가있기때문에다형성획득측면서인터페이스상속보다안전하지못하다. 3. 다형성 (Polymorphism) 기반클래스의행동을상속한클래스에서재정의하는것 8 출처 : 실전코드로배우는실용주의디자인패턴 ( 사이텍미디어, 송치형 )

9 2. What is an Object

What is an Object Class = User Defined Data Type VS. Object = Service Provider 10

What is an Object Object (Service Provider) 무엇을하는가 (WHAT) 하는연산으로정의되어야한다 ( 변화하지않는것 ). 어떻게 (HOW) 연산을수행하는가는철저히은닉되어야한다 ( 변화하는것 ). 11

12 3. Modeling

Modeling Read World Analysis/Design Test? Model Programming System Modeling Model 은어떤것이실제로도잘동작하는지알아보려고만드는것이다. Test 목적 : 실제물건을만드는것보다훨씬적은비용으로설계가제대로되었는지판단할수있다. Modeling 은 Model 을만들어테스트해보는과정을이야기한다. 13

Modeling Software Development 입장에서 Model 은? Model 은개발된소프트웨어프로젝트의하나또는그이상의측면들을표현하는 UML 다이어그램의집합이다. 결론 UML 은 Modeling 의필수도구이다. 14

15 Part 2. UML 기초

16 1. Usecase Diagram

Usecase Diagram 사용자 (Actor) 가보낸자극 자극하나에대한반응으로시스템이진행하는 ( 정보요청 / 제공등상호작용 ) 눈에보이는이벤트들의흐름 흐름을표현한다. Relationship System System Name Usecase Name Actor Name 17 사용자 (Actor) 은시스템외부에존재하며시스템과상호작용하는것. 유스케이스 (Usecase) 은사용자 (Actor) 의관점에서작성된시스템의동작하나를기술한것. 목적 사용자의시각에서시스템의범위와기능을파악할수있다.

Usecase Diagram Notiation Actor and Usecase Actor and Actor Usecase and Usecase Association (Communication) Generalization (Inheritance) Include (Shared Service) <<include>> Extend <<extend>> (Extension Point) Extension Point Ex. 창구담당자 항공편검색항공편예약 Airline Reservation <<include>> <<include>> 적용가능한할인검색 18

19 2. Class Diagram

Class Diagram 시스템에서사용되는객체타입 ( 클래스 ) 를정의하고, 그들간에존재하는정적인관계를다양한방식으로표현한다. 목적 높은응집도 (High Cohesion), 낮은결합도 (Low Coupling) 설계를하도록강요한다. 시스템고유의유지보수성과적응성을측정하는기준 응집도은하나의클래스가하나의기능 ( 책임 ) 을온전히순도높게담당하고있는정도 결합도는클래스간의서로다른책임들이얽혀있는상호의존도의정도 20

Class Diagram class Widget Class Name Widget class Widget public: int m_nvalue; protected: long m_lvalue; private: double m_dwvalue; Class Diagram Attritue Widget + m_nvalue : int # m_lvalue : long - m_dwvalue : double Visibility Variance type Operation class Widget public: int m_nvalue; public: void Do(); protected: int Do(int nvalue); private: long Do(int nvalue, long lvalue); + + # - Widget m_nvalue : int Do( ) Do(nValue : int) : int Do(nValue : int, lvalue : long) : long 21 Parameters Return type

Class Diagram Widget class Widget public: virtual void Draw() = 0; int GetSize(); Class Diagram + Draw() + GetSize() : int 추상메소드 ( 이탤릭체 ) 추상클래스 ( 이탤릭체 ) class Widget public: virtual void Draw() = 0; virtual int GetSize() = 0; class + Draw() <<interface>> Widget + GetSize() : int Stereotype interface ( 기존 UML 요소 ) ( 새로만든 UML 요소 ) 22

Class Diagram class Widget public: virtual void Draw(); + Draw() Widget 23 class Button : public Widget public: virtual void Draw(); class Widget public: virtual void Draw() = 0; class Button : public Widget public: virtual void Draw(); Class Diagram + Draw() Button Implement Inheritance = Generalization (OOP) (UML) + Draw() + Draw() <<interface>> Widget Button Interface Inheritance = Realization (OOP) (UML)

Class Diagram Association name class Widget public: list<tool*> m_ptool; Role name Select Widget class Tool Class Diagram Widget +m_ptool 0..* Multiplicity Tool class Widget public: vector<tool*> m_ptool; class Tool Unidirectional Association OOP 에서직접적으로지원하는개념이아니다. 24

Class Diagram class Computer public: Printer* m_pprinter; Computer Aggregation +m_pprinter Printer class Printer Computer +m_pprinter Printer class Computer public: Printer* m_pprinter; public: Computer() m_pprinter = new Printer; ~Computer() delete m_pprinter; Class Diagram Composition Ex. Aggregation Computer Computer Computer Printer Printer ( O ) ( O ) ( O ) ( O ) Ex. Compositon Computer Computer keyboard keyboard mouse mouse 25 ( O ) ( X ) ( X )

Class Diagram class Widget public: void Draw(Graphics* pgraphics); class Graphics Class Diagram Widget + Draw(pGraphics : Graphics*) Graphics Dependency 26

27 3. Sequence Diagram

Sequence Diagram 객체간의동적인상호관계를시간순서에따라표현한다. 목적 시스템의문제해결을위한전체흐름을쉽게파악할수있다. 28

Sequence Diagram Object Name Class Name : ShapeFactory MakeShape class ShapeFactory public: void MakeShape(); Sequence Diagram Method Message Time Life Line Activation 29

Sequence Diagram Return : ShapeFactory class ShapeFactory public: Shape* MakeShape() return new Rectangle; Sequence Diagram shape := MakeShape shape : Rectange class Rectangle : public Shape Return Message 30

Sequence Diagram : ShapeFactory shape : Rectange class ShapeFactory DeleteShape private: Shape* m_pshape; public: void DeleteShape() Sequence Diagram delete m_pshape; End of Object Life 31

Sequence Diagram ShapeFactory MakeShape class ShapeFactory private: static void MakeShape(); Sequence Diagram 32

Sequence Diagram class Log public: Log() _beginthreadex(, ThreadFunc, ); Write : Log unsigned int WINAPI ThreadFunc( ) while(isrunning) // 로그데이터처리 void Write(string strlog) // 로그데이터추가만수행 // 로그데이터처리는 ThreadFunc 에서 Sequence Diagram Asynchronous Message 33

34 Part 3. UML 실전

35 1. The Fragile-Base-Class Problem

깨지기쉬운기반클래스문제 (The Fragile-Base-Class Problem) class ArrayList public: void Add(int nindex, String strdata) 36 String Remove(int nindex) void Clear() // 모든데이터삭제 class Stack : public ArrayList private: int m_ntopofstack; public: void Push(String strdata) Add(m_nTopOfStack++, strdata); String Pop() return Remove(--m_nTopOfStack); Stack stack = new Stack(); stack.push("1"); stack.push("2"); stack.clear(); stack.push( 3 ); // m_ntopofstack 가올바른위치를지정할수없다 clear 메소드호출로인하여스택인텍스 (m_ntopofstack) 가올바른위치를지정할수없게된다. 즉, 원하지않는메소드 (clear) 까지모두상속받기때문이다.

깨지기쉬운기반클래스문제 (The Fragile-Base-Class Problem) 단순해결책 1. Stack 내부의상태를변경하는모든메소드 (clear, ) 를상속받는다. 기반클래스에 clear 와같은메소드를추가하는경우에는속수무책이다. 2. clear 메소드가예외를던지도록상속받는다. 기반클래스의규약은파생클래스가기반클래스의몇몇메소드가작동하길원하지않을때예외를던진다고말해주지않는다. 예외로인하여클라이언트는다형성을이용한코딩을하지못하게된다 (LSP 위반 ). 컴파일타임에러 ( 해당메소드를찾을수없음 ) 를런타임으로옮기게된다. 37

깨지기쉬운기반클래스문제 (The Fragile-Base-Class Problem) Implement Inheritance 보다는 Composition 을선호하자 Implement Inheritance class ArrayList public: void Clear() Favor Object Composition(with Interface Inheritance) over Class Implementation. (Implement Inheritance) // 모든데이터삭제 class Stack : public ArrayList private: int m_ntopofstack; public: Stack() : m_ntopofstack(0) void Push(String strdata) Add(m_nTopOfStack++, strdata); String Pop() return Remove(--m_nTopOfStack); class Stack private: int m_ntopofstack = 0; ArrayList m_data; Composition public: Stack() : m_ntopofstack(0) public void Push(String strdata) m_data.add(m_ntopofstack++, strdata); public String Pop() return m_data.remove(--m_ntopofstack); 38

깨지기쉬운기반클래스문제 (The Fragile-Base-Class Problem) class Stack private: int m_ntopofstack = 0; ArrayList m_data; Stack stack = new Stack(); public: Stack() : m_ntopofstack(0) stack.push("1"); stack.push("2"); stack.clear(); public void Push(String strdata) m_data.add(m_ntopofstack++, strdata); public String Pop() return m_data.remove(--m_ntopofstack); clear 메소드호출로인하여컴파일러에러가발생된다. 즉, 구현상속으로인한문제점 ( 런타임시발생될에러가능성 ) 을제거할수있다. 39

40 2. Customer Requirement

Customer Requirement Log +Write(const void*, UINT) 요구사항 : Log 데이터를 File과 DB에출력한다. void Log::Write(const void* lpbuf, int nlen) // File 출력 요구사항구현 1. 변수추가 2. 함수추가 3. 구현상속 41

Customer Requirement void Log::Write(const void* lpbuf, int nlen) 1. 변수추가 if( 출력판단 ) // File 출력 else // DB 출력 2. 함수추가 int _tmain(int argc, _TCHAR* argv[])... if( 출력판단 ) plog->writefile( ); else plog->writedb( );... 3. 구현상속 class Log virtual void Write(const void*, UINT) //do something... 42 추가요구사항 : Log 데이터를 Window 에출력한다. 추가요구사항구현은? 1. 변수추가 : 조건문수정필요 2. 함수추가 : 조건문수정필요, 함수추가필요 (WriteWindow) 3. 구현상속 : 깨지기쉬운베이스클래스및불안정한다형성획득의잠재적문제소유 class LogFile : public Log virtual void Write(const void*, UINT) // File 출력 class LogDB : public Log virtual void Write(const void*, UINT) // DB 출력

43 3. Object-Oriented Design

Object-Oriented Design Object-Oriented Design Principles 1. SRP(Single Responsibility Principle) : 단일책임원칙 2. DIP(Dependency Inversion Principle) : 의존관계역전의원칙 3. ISP(Interface Segregation Principle) : 인터페이스분리의원칙 4. LSP(Liskov Substitution Principle) : 리스코프대체원칙 5. OCP(Open-Closed Principle) : 개방폐쇄원칙 44

Customer Requirement Object-Oriented Design Log 데이터를 File 에출력한다. 동기화처리된 Buffered Memory 를이용하여 File 에출력한다 ( 속도향상 ). 적용전 File System 적용후 Buffered Memory File System Log::Write Log::Write Log::Write Log::Write 동기화처리 Log::Write Log::Write Write 45 접근횟수 : 3 접근횟수 : 1 Log 데이터를 Window 에출력한다. 동기화처리하여 Window 에출력한다 ( 멀티스레드지원 ). File과 Window Stream을생성한다. 생성이제한된 Log를생성한다 ( 전역적접근 ).

Code Reuse Customer Requirement Object-Oriented Design Log 데이터를 File 에출력한다. 동기화처리된 Buffered Memory 를이용하여 File 에출력한다 ( 속도향상 ). Log 데이터를 Window 에출력한다. 동기화처리하여 Window 에출력한다 ( 멀티스레드지원 ). File 과 Window 을생성한다. 생성이제한된 Log 를생성한다 ( 전역적접근 ). 46 Sub-HOW : 동기화처리, Buffered Memory Object 식별 WHAT : 출력 WHAT : 생성 WHAT : 생성 HOW : File, Window HOW : File, Window HOW : 생성이제한된 Log

WHAT HOW : 출력 : File, Window WHAT HOW : 생성 : File, Window Sub-HOW : 동기화처리, Buffered Memory WHAT HOW : 생성 : 생성이제한된 Log Logical Physical Client WHAT HOW WHAT, SRP FileOutputStreamFactory Sub - HOW <<interface>> IOutputStreamFactory +Create() : IOutputStream* OCP(LSP) Client DIP WHAT/HOW, SRP 위반 HOW Log #Log +Create() : Log* +SetLog(IOutputStream*) +Write(const void*, UINT) HOW DIP WinOutputStreamFactory FileOutputStream <<create>> <<create>> DIP Code Reuse WHAT, SRP <<interface>> IOutputStream +Write(const void*, UINT) WinOutputStream Sub-HOW OCP(LSP) SyncOutputStream DIP DecoratorOutputStream OCP(LSP) BufferedOutputStream 47

Object-Oriented Design File 출력 Window 출력 48 IOutputStream* FileOutputStreamFactory::Create() IOutputStream *pfile, *pbuffered, *psync; pfile = new FileOutputStream; pbuffered = new BufferedOutputStream(pFile); psync = new SyncOutputStream(pBuffered); return psync; IOutputStream* WinOutputStreamFactory::Create() IOutputStream *pwin, *psync; Code Reuse pwin = new WinOutputStream; psync = new SyncOutputStream(pWin); return psync; void Client::Init() Log::Create()->SetOutputStream(m_pFactory->Create()); void Client::Log( ) Log::Create()->Write(lpBuf, nlen); 재사용가능한설계 Open-Closed Principle 확장에대해열려있고, 수정에는대해닫혀있다

Object-Oriented Design Pattern Summary Singleton Strategy 49 WHAT, SRP FileOutputStreamFactory <<interface>> IOutputStreamFactory +Create() : IOutputStream* OCP(LSP) DIP WHAT/HOW, SRP 위반 HOW Log HOW DIP WinOutputStreamFactory FileOutputStream <<create>> Abstract Factory Client #Log +Create() : Log* +SetLog(IOutputStream*) +Write(const void*, UINT) <<create>> DIP Decorator WHAT, SRP <<interface>> IOutputStream Write(const void*, UINT) OCP(LSP) WinOutputStream Sub-HOW SyncOutputStream DIP DecoratorOutputStream OCP(LSP) BufferedOutputStream

50 4. Design Pattern in Practice

Customer Requirement Design Pattern in Practice Log 데이터를 DB 에출력 ( 저장 ) 한다. HOW ( 세부구현, 변화는것 ) DBOutputStream WHAT ( 외부와의계약, 변화지않는것 ) DBOutputStream 를생성한다. 출력 ( 저장 ) WHAT delegation delegation 동기화처리 Sub-HOW Buffered Memory Sub-HOW DB HOW 51 HOW ( 세부구현, 변화는것 ) DBOutputStreamFactory WHAT ( 외부와의계약, 변화지않는것 ) 동기화처리된 Buffered Memory 를이용하여 DB 에출력 ( 저장 ) 한다. Sub-HOW delegation Sub-HOW delegation HOW WHAT

Design Pattern in Practice WHAT : 출력 WHAT : 생성 HOW : DBOutputStream HOW : DBOutputStreamFactory Sub-HOW : 동기화처리, Buffered Memory Object-Oriented Design WHAT Client WHAT <<interface>> IOutputStreamFactory +Create() : IOutputStream* Log #Log +Create() : Log* +SetLog(IOutputStream*) +Write(const void*, UINT) <<interface>> IOutputStream +Write(const void*, UINT) HOW FileOutputStreamFactory WinOutputStreamFactory DBOutputStreamFactory HOW DBOutputStream <<create>> <<create>> FileOutputStream WinOutputStream Sub-HOW SyncOutputStream DecoratorOutputStream BufferedOutputStream 52

Design Pattern in Practice File 출력 DB 출력 53 IOutputStream* FileOutputStreamFactory::Create() IOutputStream *pfile, *pbuffered, *psync; pfile = new FileOutputStream; pbuffered = new BufferedOutputStream(pFile); psync = new SyncOutputStream(pBuffered); return psync; Code Reuse IOutputStream* DBOutputStreamFactory::Create() IOutputStream *pdb, *pbuffered, *psync; pdb = new DBOutputStream; pbuffered = new BufferedOutputStream(pFile); psync = new SyncOutputStream(pBuffered); return psync; void Client::Init() Log::Create()->SetOutputStream(m_pFactory->Create()); void Client::Log( ) Log::Create()->Write(lpBuf, nlen); 재사용가능한설계 Open-Closed Principle 확장에대해열려있고, 수정에는대해닫혀있다

54 5. Summary

Summary Object = Service Provider 55