whole part pattern

Post on 16-Aug-2015

649 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Whole-Part Pattern

목 차

Presentation Abstrac-tion

Control Pattern

Whole-Part Design Pattern

의미적 Component 들의 Aggregate 에 도움Whole 객체에서 Part 들 캡슐화Whole 은 Part 들간 협력 관계 조직화자체 기능에 대한 공통인터페이스 제공Part 에 직접 액세스 할수 없음

집합 객체를 구현해야 한다 !!!

예 )

마우스 휠 레이저 몸 통

마우스

하위의 부품이 상위의 부품에 계층적

Version up( 각제품 변경 )!= 인터페이스

기본적으로 사용자의 시각에서 기초함

struct D3DXVECTOR2{float x;float y;

};

enum meventType{fromWheel = 100,fromLager,frombody

};

class Controlable{public:

virtual void updateMouse(meventType mtype) = 0;

};

class MouseWheel{protected:

Controlable* _signalMouseWheel;float tAxis;

public:void Initialize( Controlable& _target );void rotationWhile(float& vAxis);const float& getAxis() const;

};

class Mouselager{protected:

Controlable* _signalLager;D3DXVECTOR2 pt;

public:

void Initialize( Controlable& _target );void movePosition(float& vX, float&

vY);const D3DXVECTOR2& getMove()

const;

};

class Mousebody{protected:

Controlable* _signalbody;

public:void Initialize( Controlable& _target );void sendInterrupt(meventType _type,

void* _value);

};

class Mouse : public Controlable{protected:

MouseWheel* _mwheel;Mouselager* _mlager;Mousebody* _mbody;

public:void Initialize();virtual void updateMouse(meventType

mtype);};

#include "Mouse.h"

void Mouse::Initialize(){

_mwheel = new MouseWheel;_mwheel->Initialize(*this);_mlager = new Mouselager;_mlager->Initialize(*this);_mbody = new Mousebody;_mbody->Initialize(*this);

}

void Mouse::updateMouse( meventType mtype )

{switch(mtype){case frombody : _mbody->sendInterrupt(frombody, 0);break;case fromLager:_mbody->sendInterrupt(fromLager, (void*)&_mlager->getMove());break;case fromWheel:_mbody-

>sendInterrupt( fromWheel ,(void*)&_mwheel->getAxis());

break;}

}

void MouseWheel::Initialize( Controlable& _target ){

_signalMouseWheel = &_target;}

void MouseWheel::rotationWhile( float& vAxis ){

tAxis = vAxis;_signalMouseWheel->update-

Mouse(fromWheel);}

const float& MouseWheel::getAxis() const{

return tAxis;}

void Mouselager::Initialize( Controlable& _tar-get ){

_signalLager = &_target;

}

void Mouselager::movePosition( float& vX, float& vY ){

pt.x = vX;pt.y = vY;

}

const D3DXVECTOR2& Mouselager::getMove() const{

return pt;}

void Mousebody::Initialize( Controlable& _target ){

_signalbody = &_target;}

void Mousebody::sendInterrupt(meventType _type, void* _value){

// 인터럽트발생 ~~~ // int86(0x00,R,R);}

문 제

거의 모든 소프트웨어 시스템에서 객체들은 다른 객체들의 조합으로 이루어져 있다 .

분자와 원자의 관계와 같이 , 하위 객체에서 없던 동작이 상위 객체에서 드러나는 경우

해 답

더 작은 객체들 캡슐화 , 클라이언트에서 컴포넌트에 직접 액세스 못하도록 막는다 . 액세스는 인터페이스를 통해한다 .

복합 객체는 작은 객체로 분해 , 또는 기존에 있던 객체들로 구성 .그래야 재사용성 , 교체성을 지원 , 구성 객체들을 다른 유형의 집합 객체로 재조합할 수 있다 .클라이언트는 집합 객체의내부 구성 부분에 직접 액세스를 허용하지 않는 최소단위 객체로 인지해야 한다 .

Whole-Part Pattern 유형

집합 객체는 하나의 의미적 단위

어셈블리 - 파트(assembly-part) 관계

컨테이너 - 컨텐츠(container-contents) 관계

컬렉션 - 멤버 (collection-members) 관계 멤버들을 차례로 각 멤버의

오퍼레이션을 수행

파트들만큼 민접한 결함이 아님 .   콘텐트들은 동적으로 추가 , 제거 가능

생산물의 하위나 하위 부분들에 해당하는 ' 파트 '들로 구분

장 점

Part 객체의 가변성 지원 역할의 분리 가능

재사용성 지원

단 점

우회 방식 때문에 효율성이 떨어짐 .

Part 객체들로 분해하는 과정이 복잡

Presentation-Abstraction-Control패턴

계층 구조를 이룬 에이전트들이 서로 협력을 이루어 상호작용

소프트웨어 시스템의 구조

Presentation-Abstraction-Control패턴

모든 에이전트는 어플리케이션 기능의 특정 측면

각 에이전트는 프리젠테이션 , 추상 , 컨트롤 , 이렇게 세 가지 컴포넌트로 구성

이는 사람 - 컴퓨터 간에 이루어지는 상호작용으로부터 통신하는 에이전트 및 핵심기능 분리

패턴 구조Top Level PAC agent

시스템의 핵심 기능과 사용자와 인터페이스 역할 담당

Bottom Level PAC agent

하나가 하나의 기능을 수행또는

둘이상이 하나의 기능 협력

Intermediate Level PAC agent

둘 이상의 agent 가 수행해야 하는 기능을

가질 때 이를 조합

예 )

Top Level Agent는 계층 구조를 조정 , 사용자와 시스템과의 상호작용의 데이터를 저장 , 원본 데이터 관리

Bottom Level Agent는 실질적인 기능을 수행하는 단위이며 , 하나의 기능 , 쓰레드 , 프로세스 일 수 있다 .

Intermediate Level Agent는 기능 수행을 위한 하위 에이전트 조합을 만들거나 하위 에이전트로 부터 데이터를 상위 에이전트로 전달하는 역할

Presentation 컴포넌트는 시각적인 표현을 나타내며 , 에이전트의 형태에 따라 구현하지 않을 수도 있다 .

Abstraction 컴포넌트는 데이터를 가지며 , 이를 핸들링한다 . 원본 데이터는 Top Level에만 있고 , 나머지 에이전트는 독립적인 데이터를 가진다 .

Control 컴포넌트는 Presentation과 Abstraction을 연결해주는 역할과 다른 에이전트간의 통신을 담당

Intermediate Level Agent는 선택가능 (Optional)하며 , Top Level agent와 Bot-tom Level Agent로만 구성될 수도 있음

정치선거 시스템에서의 PAC 구조

장 점

관련된 것들의 분리

교체와 확장성의 지원

    * 상호작용하는 어플리케이션은 top-level agent 가 하나있고 몇몇 intermediate-level agent 들 그리고 더욱 많은 bottom-level agent들이 있어야 한다 . 모든 대리자 (agent) 들은 어플리케이션의 기능의 특정 모듈을 담당하고 있으며 presentation,  abstraction, control 의 세개의 컴포넌트로 이루어져 있다 .

    * 대리자의 presentation 컴포넌트는 PAC 대리자의 시각적 행위를 제공한다 . abstraction 컴포넌트는 대리자 밑에 있는 데이터 모델을 유지관리하며 이 데이터를 작동할수 잇는 기능들을 제공한다 . con-trol 컴포넌트는 presentation 컴포넌트와 abstraction 컴포넌트를 서로 연결하며 다른 PAC 대리자들과 통신할 수 있는 기능을 대리자에게 제공한다 .

top related