닷넷 개발자를 위한 패턴이야기

70
Pattern Story Pattern Story (for .NET (for .NET Developers) Developers) YoungSu, Son YoungSu, Son [email protected] [email protected] Microsoft MVP Microsoft MVP Devpia Architecture&Design Sysop Devpia Architecture&Design Sysop Devpia .NET Framework 3.0 Sysop Devpia .NET Framework 3.0 Sysop Samsung Electronics Home Solution Group Samsung Electronics Home Solution Group

Upload: youngsu-son

Post on 10-May-2015

1.323 views

Category:

Technology


5 download

DESCRIPTION

GoF 패턴의 원칙과 여러가지 패턴을 소개하고, 패턴들이 하나의 군을 이루어 활용되는 예를 설명한다.

TRANSCRIPT

Page 1: 닷넷 개발자를 위한 패턴이야기

Pattern StoryPattern Story (for .NET Developers)(for .NET Developers)Pattern StoryPattern Story

(for .NET Developers)(for .NET Developers)

YoungSu, SonYoungSu, [email protected]@devpia.com

Microsoft MVPMicrosoft MVPDevpia Architecture&Design SysopDevpia Architecture&Design SysopDevpia .NET Framework 3.0 SysopDevpia .NET Framework 3.0 Sysop

Samsung Electronics Home Solution GroupSamsung Electronics Home Solution Group

YoungSu, SonYoungSu, [email protected]@devpia.com

Microsoft MVPMicrosoft MVPDevpia Architecture&Design SysopDevpia Architecture&Design SysopDevpia .NET Framework 3.0 SysopDevpia .NET Framework 3.0 Sysop

Samsung Electronics Home Solution GroupSamsung Electronics Home Solution Group

Page 2: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 22

AgendaAgenda

Pattern and Model with Etymon.Pattern and Model with Etymon.

GoF 2 Principles.GoF 2 Principles.

Basic Patterns with .NETBasic Patterns with .NET

Strategy PatternStrategy Pattern

Template Method PatternTemplate Method Pattern

Component Configuration PatternComponent Configuration Pattern

Reflection PatternReflection Pattern

Pipe & Filter PatternPipe & Filter Pattern

Factory PatternFactory Pattern

Observer PatternObserver Pattern

Chain-of-Responsibility PatternChain-of-Responsibility Pattern

Relationship between Patterns.Relationship between Patterns.

Introduce to Pattern Explore & BooksIntroduce to Pattern Explore & Books

Page 3: 닷넷 개발자를 위한 패턴이야기

Pattern & ModelPattern & Model

What’s the Design Patten?What’s the Design Patten?

DessinDessin

Pattern is Father!Pattern is Father!

The Definition of Design PatternThe Definition of Design Pattern

Model is MotherModel is Mother

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 33

Page 4: 닷넷 개발자를 위한 패턴이야기

What’s the Design Pattern?What’s the Design Pattern?

Page 5: 닷넷 개발자를 위한 패턴이야기

DessinDessin

DessinDessin데셍하다데셍하다살짝 밑그림을 그리는 작업살짝 밑그림을 그리는 작업

DesignDesignde = awayde = away

sign = Notesign = Note

완성품을 만들기 이전에 살짝 완성품을 만들기 이전에 살짝 뼈대를 잡는 작업뼈대를 잡는 작업

Page 6: 닷넷 개발자를 위한 패턴이야기

Pattern is FatherPattern is Father

PatternPattern 의 어원은 의 어원은

Father(Father( 아버지아버지 ) ) 에서 파생에서 파생

비슷한 생김새비슷한 생김새 , , 성격등을 성격등을

가지고 있음을 의미가지고 있음을 의미

그럼 비슷한 문제들도 그럼 비슷한 문제들도

비슷한 방법비슷한 방법 (Pattern)(Pattern) 으로 으로

해결 가능해결 가능

Page 7: 닷넷 개발자를 위한 패턴이야기

The Definition of Design PatternThe Definition of Design Pattern

좋은 좋은 S/WS/W 의 밑 그림을 잘 그릴수 있는 지침

의 밑 그림을 잘 그릴수 있는 지침 //가이드라인가이드라인

Page 8: 닷넷 개발자를 위한 패턴이야기

Model is Mother !!!Model is Mother !!!

Page 9: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 99

GoF 2 PrinciplesGoF 2 Principles

Program to an interfaceProgram to an interface,,

not to an implementationnot to an implementation

Favor Object CompositionFavor Object Composition

over Class Inheritanceover Class Inheritance

Page 10: 닷넷 개발자를 위한 패턴이야기

GoF 1GoF 1stst Principle. Principle.

Program to an interface,Program to an interface,Not to an implementation.Not to an implementation.

When you pick up your rental car..When you pick up your rental car..Push the seat all the way backPush the seat all the way back

Find an NPR stationFind an NPR station

Find the exitFind the exit

Read the Manual?Read the Manual?

Page 11: 닷넷 개발자를 위한 패턴이야기

Oh, down to lockOh, down to lock……

Page 12: 닷넷 개발자를 위한 패턴이야기

How to use a keyHow to use a key……

Page 13: 닷넷 개발자를 위한 패턴이야기

Oh, you Oh, you pushpush the PRESS the PRESS buttonbutton……

Page 14: 닷넷 개발자를 위한 패턴이야기

Who Who actually actually needs this needs this data?data?

Page 15: 닷넷 개발자를 위한 패턴이야기

Why you donWhy you don’’t read rental car t read rental car manuals manuals

You know how to drive your carYou know how to drive your car

All cars work basically All cars work basically the same waythe same way

Your rental car is a carYour rental car is a car

Therefore, you can drive your rental Therefore, you can drive your rental carcar

That isThat is……

Page 16: 닷넷 개발자를 위한 패턴이야기

GoF 2GoF 2ndnd Principle Principle

Favor Object CompositionFavor Object Compositionover Class Inheritanceover Class Inheritance

Don’t use Don’t use Inheritance??Inheritance??

Only useOnly use

Object Object Composition!Composition!

A swindlerA swindlerDeveloperDeveloper

Page 17: 닷넷 개발자를 위한 패턴이야기

The Two Towers in Object World.The Two Towers in Object World.

A Great ArchitectA Great Architect

Composition & InheritanceComposition & Inheritance areare

Two Towers in OO WorldTwo Towers in OO World

Page 18: 닷넷 개발자를 위한 패턴이야기

Inheritance and CompositionInheritance and Composition

구분구분 상속상속 객체 합성객체 합성

스타일스타일 White BoxWhite Box Black BoxBlack Box

장점장점 단순하고 사용하기 편리단순하고 사용하기 편리 ..

구조 명확구조 명확

코드 재활용코드 재활용

약한 결합력약한 결합력

동적 바인딩 가능동적 바인딩 가능

캡슐화 유지캡슐화 유지

단점단점 부모 클래스에 종속성 발생부모 클래스에 종속성 발생

유연성 감소유연성 감소

클래스 수 폭발적 증가클래스 수 폭발적 증가

캡슐화 파괴캡슐화 파괴

구조가 복잡 구조가 복잡

사용시 유의해야 함사용시 유의해야 함

객체 수 증가객체 수 증가

UML UML 구조구조

Page 19: 닷넷 개발자를 위한 패턴이야기

Composition versus Inheritance.Composition versus Inheritance.

InterviewInterview

Design Principles from Design Design Principles from Design PatternsPatterns

Eric Gamma Say Eric Gamma Say

A common misunderstandingA common misunderstanding is is that that composition doesn’t use composition doesn’t use inheritance at allinheritance at all..

RefersRefers

http://www.artima.com/lejava/http://www.artima.com/lejava/articles/designprinciplesP.htmlarticles/designprinciplesP.html

Eric GammaEric Gamma

Page 20: 닷넷 개발자를 위한 패턴이야기

Types of Inheritance.Types of Inheritance.

Interface1

+ISomething()

ConcreteClass1

+ISomething()

ConcreteClass2

+ISomething()

Impl.

+ISomething()

ImplInheritance

+ISomething()

ImplInheritance

+ISomething()

Class Interface1 {

ISomething() = 0;}

Class Impl { ISomething()

{ .. do(); ..}

}

SubtypingSubtyping SubclassingSubclassing

A Great ArchitectA Great Architect

Don’t use Don’t use

SubclassingSubclassing

Page 21: 닷넷 개발자를 위한 패턴이야기

GoF 2nd Principle.

1990’s1990’sFavor Object Composition over Class Favor Object Composition over Class Inheritance.Inheritance.

2000’s2000’sFavor Object Composition (based Favor Object Composition (based SubTyping) over SubClassing.SubTyping) over SubClassing.

Page 22: 닷넷 개발자를 위한 패턴이야기

Principles of GoF PatternPrinciples of GoF Pattern

SortAlgorithmSortAlgorithm

Sort()Sort()

BubbleSortBubbleSort

Sort()Sort()

QuickSortQuickSort

Sort()Sort()

UltraSortUltraSort

Sort()Sort()

DataArrayDataArray

SortAlgorithm* m_pSortSortAlgorithm* m_pSort

SetAlgorithm(SortAlgorithm* pSort)SetAlgorithm(SortAlgorithm* pSort)Sort()Sort()

객체합성

상속상속 (subtyping)(subtyping)

Page 23: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 2323

Basic PatternsBasic Patterns

Core Components of SW Impl.Core Components of SW Impl.

Strategy PatternStrategy Pattern

Template Method PatternTemplate Method Pattern

Component Configurator PatternComponent Configurator Pattern

Reflection PatternReflection Pattern

Pipe & Filter PatternPipe & Filter Pattern

Factory PatternFactory Pattern

Observer PatternObserver Pattern

Chain of ResponsibilityChain of Responsibility

Page 24: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 2424

Core Components of S/W Impl.Core Components of S/W Impl.

You must rememberYou must remember

3 Core Components!3 Core Components!

Great ArchitectGreat Architect

CommonCommonPartPart

ConfigurableConfigurablePartPart

VariableVariablePartPart

Page 25: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 2525

ConfigurableConfigurablePartPart

VariableVariablePartPart

Core Components of S/W Impl.Core Components of S/W Impl.

Component Component ConfiguratorConfigurator

FactoryFactory

StrategyStrategy

<<LINKS>><<LINKS>>

<<CREATES>><<CREATES>>

CommonCommonPartPart

(Modularity)(Modularity)

LogLog

SecuritySecurity

TransactionTransaction

AOPAOP

Page 26: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 2626

Strategy PatternStrategy Pattern

IntentsIntents

satellitesatellite SuperSuperComputerComputer

Do you think that Do you think that

the same logic usethe same logic use

between satellite and between satellite and

super computer?super computer?

Page 27: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 2727

Strategy Pattern in GoFStrategy Pattern in GoF

void main()

{

//pSort 라는 인터페이스를 선언한다CSort *pSort;

if (GetSystemInfo() == Low)

{

// 인공위성에서는 Bubble Sorting 사용pSort = new CBubble();

}

else

{

// 슈퍼 컴퓨터에는 Quick Sorting 사용

pSort = new CQuick();

}

pSort->Sorting();

delete pSort;

}

CSort

+Sorting()

CBubble

+Sorting()

CQuick

+Sorting()

Page 28: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 2828

Template Method PatternTemplate Method Pattern

IntentsIntents

ODBC(JDBC) APIODBC(JDBC) API

ApplicationApplication

ODBC (JDBC) Driver ManagerODBC (JDBC) Driver Manager

MSSQL DriverMSSQL Driver Oracle DriverOracle Driver

Page 29: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 2929

Template Method Pattern in GoFTemplate Method Pattern in GoF

CQueryTemplate

+doQuery()#FormatConnect()#FormatSelect()

COracleQT

#FormatConnect()#FormatSelect()

CSqlSvrQT

#FormatConnect()#FormatSelect()

class CQueryTemplate

{ public void doQuery()

{

string dbCommand;

dbCommand = FormatConnect();

dbCommand = FormantSelect(sql);

} ...}

void main()

{ //pQT 라는 인터페이스를 선언한다CQueryTemplate *pQT;

Sql sql = “select * from AA”;

if (GetDBProductInfo() = Oracle)

pQT = new COracleQT();

else

pQT = new CSqlSvrQT();

pQt->doQuery(sql);

delete pQt;

}

Inversion of ControlInversion of Control

(Hollywood Principle)(Hollywood Principle)

Page 30: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 3030

Component Configurator PatternComponent Configurator Pattern

IntentsIntents

ConfigurationConfigurationFileFile

HTTPHTTPProtocolProtocol

Text Based Text Based LogLog

ComponentComponent

DESDESRSARSA

XML BasedXML BasedLogLog

ComponentComponent

FTP ProtocolFTP Protocol

When When Change Config File InfoChange Config File Info,,

Component Component ConfigurationConfiguration (Attribute) (Attribute)

dynamically Changesdynamically Changes!!

Great ArchitectGreat Architect

Page 31: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 3131

Component Configurator in POSA2Component Configurator in POSA2

Component

+Init()+Fini()+Suspend()+Resume()+Info()

CoreComponent

CoreComponent

ComponentRepository

ComponentConfigurator

Page 32: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 3232

Component Configurator in POSA2Component Configurator in POSA2

Page 33: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 3333

Component Configurator SampleComponent Configurator Sample

<xml version =“1.0”>

<Components>

<!– Protocol 정보 선택 --><Protocol>

HTTP

</Protocol>

<!– Log 정보 선택 --><Log>

XML

</Log>

<!– 보안 알고리즘 선택 --><SecuAlgorithm>

DES

</SecuAltorithm>

</Components>

void main()

{

CMessage *pMessage = new CMessage();

if (GetComponentInfo(“Sort”) = HTTP)

pMessage->Protocol = HTTP;

else

pMessage->Protocol = FTP;

if (GetComponentInfo(“Log”) = XML)

pMessage->Protocol = XML;

else

pMessage->Protocol = TEXT;

...

pMessage->Send(“Hello”);

delete pMessage;

}

Advanced TopicAdvanced Topic

ReflectionReflection

Page 34: 닷넷 개발자를 위한 패턴이야기

Component Configurator ExampleComponent Configurator Example

App.config/Web.configApp.config/Web.configIn App.config.

<?xml version="1.0“ encoding="utf-8" ?>

<configuration>

    <appSettings>

       <add key="sqlCon" value=" 컨넥션 스트링 정의 "/>

    </appSettings>

</configuration> 

In C# Code.

System.Configuration.ConfigurationSetings.AppSetting[“sqlCon”];

Page 35: 닷넷 개발자를 위한 패턴이야기

Reflection Pattern in POSA1Reflection Pattern in POSA1

Component A UserInterface

MetaObject A MetaObject B MOP

Meta LevelMeta Level

Base LevelBase Level

Component B

usesuses usesuses usesuses usesuses

modifiesmodifies

modifiesmodifies

provides provides access toaccess to

furtherfurtherbase-levelbase-level

componentscomponents

furtherfurthermeta-levelmeta-level

componentscomponents

retrievesretrievesinformationinformation

Page 36: 닷넷 개발자를 위한 패턴이야기

ReflectionReflection ModuleBuilder AssemblyModule =

CreatedAssembly.DefineDynamicModule("MathModule","Math.dll");

TypeBuilder MathType = AssemblyModule.DefineType("DoMath", TypeAttributes.Public | TypeAttributes.Class);

System.Type [] ParamTypes = new Type[] {typeof(int),typeof(int) };

MethodBuilder SumMethod = MathType.DefineMethod("Sum",

MethodAttributes.Public, typeof(int), ParamTypes);

ParameterBuilder Param1 =

SumMethod.DefineParameter(1,ParameterAttributes.In, "num1");

ParameterBuilder Param2 =

SumMethod.DefineParameter(1,ParameterAttributes.In, "num2");

. . .

MathType.CreateType();

return CreatedAssembly;

Page 37: 닷넷 개발자를 위한 패턴이야기

ReflectionReflectionusing System;

using System.Reflection;

...

public class EmitDemoTest

{ static void Main()

{ ...

System.Type MathType = EmitAssembly.GetType("DoMath");

object[] Parameters = new object [2];

Parameters[0] = (object) (5); Parameters[1] = (object) (9);

object EmitObj = Activator.CreateInstance (MathType,false);

object Result = MathType.InvokeMember("Sum",

BindingFlags.InvokeMethod ,null,EmitObj,Parameters);

Console.WriteLine("Sum of {0}+{1} is {2}",

Parameters[0],Parameters[1],Result.ToString());

Console.ReadLine();

}

}

Page 38: 닷넷 개발자를 위한 패턴이야기

Pipe & Filter Pattern in POSA1Pipe & Filter Pattern in POSA1Protocol Handler InputOutput Handler

Protocol Pipeline

svc()

Read Request

svc()

Filter

svc()

Filter

svc()parse()

Parse Headers

svc()parse()

Perform Request

svc()perform()

Log Request

svc()log()

component->svc()io->receive_data()

Filter::svc()

parse()

Filter::svc()

perform()

Filter::svc()

log()

pipepipe ioio

componentcomponent

Page 39: 닷넷 개발자를 위한 패턴이야기

Using PipelineUsing Pipeline

PerformPerform

RequestRequest

LogLog

RequestRequest

HTTP/ 1.0 200 OK

Date: Thu, 09 Oct 01:26:00 GMT

Server: Eva/1.0

Last-Modified: Wed, 08 Oct 1997 ..

Content-Length : 12345

Content-Type : text/html

<HTML>

<TITLE> Homepage </TITLE>

..

</HTML>

any.net - -

[09/Oct/1997:01:26:00 -0500]

“GET /~jxh/home.html HTTP/1.0

ReadRead

RequestRequest

GET /~jxh/hoem.html HTTP/1.0

Connection: Keep-Alive

User-Agent: Mothra/0.1

Host: any.net

Accept: image/gif, image/jpeg, */*

ParseParse

RequestRequest

GET/users/jxh/public_thml/home.htmlHTTP /1.0

ParseParse

HeadersHeaders

CONNECTIONUSER_AGENTHOSTACCEPTACCEPTACCEPT

Keep-AliveMothra/0.1any.netimage/gifimage/jpeg*/*

Page 40: 닷넷 개발자를 위한 패턴이야기

Services Runtime LayerServices Runtime Layer

Instancing Behavior

SecurityChannel

TCP Transport Channel

UDP Transport Channel

Cross-Proc Transport Channel

Queue Transport Channel

HTTP Transport Channel

Messaging LayerMessaging Layer

Full Duplex

Channel

Reliable Messaging

Channel

CustomChannel

BehaviorsBehaviors ChannelsChannels

Transaction Behavior

CLR Type Integration Behavior

Throttling Behavior

Metadata Behavior

Error Handling Behavior

Concurrency Behavior

Custom Behavior

SecurityChannel

HTTP Transport Channel

TCP Transport Channel

UDP Transport Channel

Reliable Messaging

Channel

CustomChannel

Instancing Behavior

Custom Behavior

ContractTo Type

Behavior

Pipe & Filter in WCFPipe & Filter in WCF

Page 41: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4141

Factory PatternFactory Pattern

IntentsIntents

Main FunctionMain FunctionBased CodingBased Coding

Object OrientedObject OrientedProgrammingProgramming

Page 42: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4242

Factory Pattern (Abstract Factory)Factory Pattern (Abstract Factory)

IntentsIntents

OO DesignOO Design AdvancedAdvancedOO DesignOO Design

Page 43: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4343

Factory Pattern in GOFFactory Pattern in GOF

AbstractFactory

+CrateProduct()

Client

ConcreteFactory

AbstractProduct

ConcreteProduct

void main()

{

CMessage *pMessage = new CMessage();

if (GetComponentInfo(“Proto”) = HTTP)

pMessage->Protocol = HTTP;

else

pMessage->Protocol = FTP;

if (GetComponentInfo(“Log”) = XML)

pMessage->Protocol = XML;

else

pMessage->Protocol = TEXT;

...

pMessage->Send(“Hello”);

delete pMessage;

}

Page 44: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4444

Factory Pattern in GOFFactory Pattern in GOF

AbstractFactory

+CrateProduct()

Client

ConcreteFactory

AbstractProduct

ConcreteProduct

class CFactory

{

CMessage* GetInstance()

{

CMessage *pMessage = new CMessage();

if (GetComponentInfo(“Proto”) = HTTP)

pMessage->Protocol = HTTP;

else

pMessage->Protocol = FTP;

if (GetComponentInfo(“Log”) = XML)

pMessage->Protocol = XML;

else

pMessage->Protocol = TEXT;

...

return pMessage;

}

}

RemindsReminds

Component Configurator!!Component Configurator!!

Page 45: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4545

3 Foe Patterns3 Foe Patterns

ConfigurableConfigurablePartPart

VariableVariablePartPart

Component Component ConfiguratorConfigurator

FactoryFactory

StrategyStrategy

<<LINKS>><<LINKS>>

<<CREATES>><<CREATES>>

CommonCommonPartPart

(Modularity)(Modularity)

LogLog

SecuritySecurity

TransactionTransaction

Page 46: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4646

Observer Pattern (Misconception)Observer Pattern (Misconception)

Change

1. Observation1. Observation

2. Notification2. Notification

DataData Misconception!!

Or

Prejudices ( 편견 !)

Page 47: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4747

Observer is Notifieer!!Observer is Notifieer!!

ObserverObserver in Observer Pattern in Observer Pattern is Notifieeris Notifieer

Page 48: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4848ApplicantsApplicants

ManagerManager

Don’t Don’t Call us!!Call us!!

Hollywood PrincipleHollywood Principle

Page 49: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 4949ApplicantsApplicants

ManagerManager

Don’t Call us!Don’t Call us!

We Call You!!!We Call You!!!

Hollywood PrincipleHollywood Principle

Page 50: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 5050

Flow of Observer PatternFlow of Observer Pattern

DataData

Client (Type1)Client (Type1) Client (Type2)Client (Type2) Client (Type3)Client (Type3)

ManagerManager Client (Source)Client (Source)

1. Change1. Change2. Change2. Change

3. Notification3. Notification

Observer is Notifieer

Change

Page 51: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 5151

Observer Pattern in GoFObserver Pattern in GoF

Subject

+Attach (Observer o)+Detach (Observer o)+Notify()

ConcreteSubject

Observer

+Update ()

ConcreteObserver

Page 52: 닷넷 개발자를 위한 패턴이야기

Publisher-Subscriber ReplicationPublisher-Subscriber Replication

DB PublisherDB Publisher

DB SubscriberDB Subscriber

DB SubscriberDB Subscriber

DB SubscriberDB Subscriber

ReferenceReference

ReferenceReference

ReferenceReference

Change

Page 53: 닷넷 개발자를 위한 패턴이야기

With Today’s PatternsWith Today’s Patterns

Configuration FileConfiguration FileApp.configApp.configWeb.configWeb.config

HandlerHandler

Client AClient A

Client BClient B

Overhead!!

File I/O

LoadLoad

Get InfoGet InfoChangeChange

Config FileConfig File

NotifiyNotifiy

Page 54: 닷넷 개발자를 위한 패턴이야기

With Today’s PatternsWith Today’s Patterns

Configuration FileConfiguration FileApp.configApp.configWeb.configWeb.config

HandlerHandler

Client AClient A

LoadLoad

Get InfoGet InfoChangeChange

Config FileConfig File

NotifiyNotifiy

A Smart DeveloperA Smart Developer

FileSystemWatcherFileSystemWatcher

.NotifyFilter.NotifyFilter

Page 55: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 5555

Chain of ResponsibilityChain of Responsibility

IntentsIntents

Page 56: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 5656

Chain of ResponsibilityChain of Responsibility

The Last SolutionThe Last Solution바퀴벌레 팩바퀴벌레 팩

http://ajujoa.com/2460506

Page 57: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 5757

Chain of Responsibility in GoFChain of Responsibility in GoF

Client Handler

+HandleRequest()

ConcreteHandler

+successor+successor

Page 58: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 5858

Chain Of Responsibilty Chain Of Responsibilty (cont’d)(cont’d)Design StrategyDesign Strategy

The First HandlerThe First HandlerConsider ProbabilityConsider ProbabilityIn order of Frequency of Use, In order of Frequency of Use,

Consist of Handler SequencesConsist of Handler Sequences

Role of The Last HandlerRole of The Last HandlerMy ParentsMy ParentsSolve every problems! Solve every problems!

Known UseKnown UseException Handling MechanismException Handling Mechanism

Page 59: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 5959

ReviewReview

StrategyStrategySupport Algorithm that Support Algorithm that Context ConsidersContext Considers

Template MethodTemplate MethodStrategy Pattern + Strategy Pattern + TemplateTemplate

Component Configurator & ReflectionComponent Configurator & ReflectionMetadata Based ProgrammingMetadata Based Programming

Pipe & Filter PatternPipe & Filter PatternSupport Plug-in FunctionalitySupport Plug-in Functionality

ObserverObserverInversion of Control Inversion of Control (IoC)(IoC)

Chain of ResponsibilityChain of ResponsibilityException Handling MechanismException Handling Mechanism

Page 60: 닷넷 개발자를 위한 패턴이야기

Pattern ExplorePattern Explore

Page 61: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 6161

How to Study Pattern?How to Study Pattern?

Page 62: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 6262

Architectural PatternArchitectural Pattern(POSA1)(POSA1)

Layer Layer

Pipe & FilterPipe & Filter

Broker Broker

Master SlaveMaster Slave

Client – DispatcherClient – Dispatcher

Forwarder-ReceiverForwarder-Receiver

Model – ViewModel – View

ControllerController

Presentation –Presentation –Abstraction - ControlAbstraction - Control

ReflectionReflection

Counted PointerCounted Pointer

BlackboardBlackboard

Page 63: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 6363

Patterns Patterns For Concurrent & Networked Object For Concurrent & Networked Object (POSA2)(POSA2)

Page 64: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 6464

Patterns for Resource ManagementPatterns for Resource Management(POSA3)(POSA3)

Resource AcquisitionResource AcquisitionLookupLookup

Lazy AcquisitionLazy Acquisition

Eager AcquisitionEager Acquisition

Partial AcquisitionPartial Acquisition

Resource LifecycleResource LifecycleCachingCaching

PoolingPooling

CoordinatorCoordinator

Resource Lifecycle Resource Lifecycle ManagerManager

Resource ReleaseResource ReleaseLeasingLeasing

EvictorEvictor

Page 65: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 6565

Refactoring & Anti-PatternsRefactoring & Anti-Patterns

Page 66: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 6666

Various PatternsVarious Patterns

Page 67: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 6767

Various PatternsVarious Patterns

Page 68: 닷넷 개발자를 위한 패턴이야기

ReferencesReferences

Frank Buschmann et al, “Frank Buschmann et al, “Pattern-Oriented Software Architecture : Pattern-Oriented Software Architecture : A System of PatternsA System of Patterns”, Volume 1, Wiley”, Volume 1, Wiley

Douglas Schmidt et al, “Douglas Schmidt et al, “Pattern-Oriented Software ArchitecturePattern-Oriented Software Architecture”,”,Volume 2, WileyVolume 2, Wiley

Eric Gamma et al, “Eric Gamma et al, “Design Patterns : Elements of Reusable Object Design Patterns : Elements of Reusable Object Oriented SoftwareOriented Software” , Addison Wesley” , Addison Wesley

Pipe & Filter Pattern, Pipe & Filter Pattern, http://www.codeproject.com/cs/design/PipesAndFilters.asphttp://www.codeproject.com/cs/design/PipesAndFilters.asp

Reflection Pattern, Reflection Pattern, http://www.codeproject.com/csharp/introreflection.asphttp://www.codeproject.com/csharp/introreflection.asp

Page 69: 닷넷 개발자를 위한 패턴이야기

ReferencesReferences

FileSystemWatcher.NotifyFilterFileSystemWatcher.NotifyFilter

http://msdn2.microsoft.com/en-us/library/http://msdn2.microsoft.com/en-us/library/system.io.filesystemwatcher.notifyfilter(VS.80).aspxsystem.io.filesystemwatcher.notifyfilter(VS.80).aspx

Pattern ExplorePattern Explore

http://www.codeplex.com/Wiki/View.aspx?http://www.codeplex.com/Wiki/View.aspx?ProjectName=guidanceExplorerProjectName=guidanceExplorer

Devpia A&D Free Online LectureDevpia A&D Free Online Lecture

http://www.devpia.com/NewStudy/LectureList.aspx?http://www.devpia.com/NewStudy/LectureList.aspx?ClassA=A&ClassB=05&ClassC=01ClassA=A&ClassB=05&ClassC=01

Page 70: 닷넷 개발자를 위한 패턴이야기

04/11/2304/11/23 Devpia A&D EVADevpia A&D EVA 7070

QuestionsQuestions

Give me Question Give me Question

about Patterns!!about Patterns!!

Devpia Architecture & Design Q&ADevpia Architecture & Design Q&A http://www.devpia.com/Maeul/Contentshttp://www.devpia.com/Maeul/Contents/List.aspx?BoardID=4&MAEULNo=4/List.aspx?BoardID=4&MAEULNo=4