• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
닷넷 개발자를 위한 패턴이야기
 

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

on

  • 1,425 views

GoF 패턴의 원칙과 여러가지 패턴을 소개하고,

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

Statistics

Views

Total Views
1,425
Views on SlideShare
1,413
Embed Views
12

Actions

Likes
1
Downloads
22
Comments
0

3 Embeds 12

http://nigayo.com 6
http://www.heej.net 4
http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • POSA2/Dispatcher 06/02/09 Devpia A&D Eva

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

  • Pattern Story (for .NET Developers) YoungSu, Son [email_address] Microsoft MVP Devpia Architecture&Design Sysop Devpia .NET Framework 3.0 Sysop Samsung Electronics Home Solution Group
  • Agenda
    • Pattern and Model with Etymon.
    • GoF 2 Principles.
    • Basic Patterns with .NET
      • Strategy Pattern
      • Template Method Pattern
      • Component Configuration Pattern
      • Reflection Pattern
      • Pipe & Filter Pattern
      • Factory Pattern
      • Observer Pattern
      • Chain-of-Responsibility Pattern
    • Relationship between Patterns.
    • Introduce to Pattern Explore & Books
    06/02/09 Devpia A&D EVA
  • Pattern & Model
    • What’s the Design Patten?
    • Dessin
    • Pattern is Father!
    • The Definition of Design Pattern
    • Model is Mother
    06/02/09 Devpia A&D EVA
  • What’s the Design Pattern?
  • Dessin
    • Dessin
      • 데셍하다
      • 살짝 밑그림을 그리는 작업
    • Design
      • de = away
      • sign = Note
    • 완성품을 만들기 이전에 살짝 뼈대를 잡는 작업
  • Pattern is Father
    • Pattern 의 어원은
    • Father( 아버지 ) 에서 파생
    • 비슷한 생김새 , 성격등을
    • 가지고 있음을 의미
    • 그럼 비슷한 문제들도
    • 비슷한 방법 (Pattern) 으로
    • 해결 가능
  • The Definition of Design Pattern 좋은 S/W 의 밑 그림을 잘 그릴수 있는 지침 / 가이드라인
  • Model is Mother !!!
  • GoF 2 Principles
    • Program to an interface ,
    • not to an implementation
    • Favor Object Composition
    • over Class Inheritance
    06/02/09 Devpia A&D EVA
  • GoF 1 st Principle. Program to an interface, Not to an implementation.
    • When you pick up your rental car..
      • Push the seat all the way back
      • Find an NPR station
      • Find the exit
    • Read the Manual?
  • Oh, down to lock …
  • How to use a key …
  • Oh, you push the PRESS button …
  • Who actually needs this data?
  • Why you don ’ t read rental car manuals
    • You know how to drive your car
    • All cars work basically the same way
    • Your rental car is a car
    • Therefore, you can drive your rental car
    • That is …
    The Power of Sameness
  • GoF 2 nd Principle Favor Object Composition over Class Inheritance Don’t use Inheritance?? Developer Only use Object Composition! A swindler
  • The Two Towers in Object World. Composition & Inheritance are Two Towers in OO World A Great Architect
  • Inheritance and Composition 구분 상속 객체 합성 스타일 White Box Black Box 장점 단순하고 사용하기 편리 . 구조 명확 코드 재활용 약한 결합력 동적 바인딩 가능 캡슐화 유지 단점 부모 클래스에 종속성 발생 유연성 감소 클래스 수 폭발적 증가 캡슐화 파괴 구조가 복잡 사용시 유의해야 함 객체 수 증가 UML 구조
  • Composition versus Inheritance.
    • Interview
      • Design Principles from Design Patterns
    • Eric Gamma Say
      • A common misunderstanding is that composition doesn’t use inheritance at all .
    • Refers
    • http://www.artima.com/lejava/articles/designprinciplesP.html
    Eric Gamma
  • Types of Inheritance. Class Interface1 { ISomething() = 0; } Class Impl { ISomething() { .. do(); .. } } Subtyping Subclassing Interface1 +ISomething() Concrete Class1 +ISomething() Concrete Class2 +ISomething() Impl. +ISomething() Impl Inheritance +ISomething() Impl Inheritance +ISomething() A Great Architect Don’t use Subclassing
  • GoF 2 nd Principle.
    • 1990’s
      • Favor Object Composition over Class Inheritance.
    • 2000’s
      • Favor Object Composition (based SubTyping) over SubClassing.
  • Principles of GoF Pattern 객체합성 상속 (subtyping) SortAlgorithm Sort() BubbleSort Sort() QuickSort Sort() UltraSort Sort() DataArray SortAlgorithm* m_pSort SetAlgorithm(SortAlgorithm* pSort) Sort()
  • Basic Patterns
    • Core Components of SW Impl.
    • Strategy Pattern
    • Template Method Pattern
    • Component Configurator Pattern
    • Reflection Pattern
    • Pipe & Filter Pattern
    • Factory Pattern
    • Observer Pattern
    • Chain of Responsibility
    06/02/09 Devpia A&D EVA
  • Core Components of S/W Impl. 06/02/09 Devpia A&D EVA You must remember 3 Core Components! Common Part Configurable Part Variable Part Great Architect
  • Core Components of S/W Impl. 06/02/09 Devpia A&D EVA Configurable Part Variable Part Component Configurator Factory Strategy <<LINKS>> <<CREATES>> Common Part (Modularity) Log Security Transaction AOP
  • Strategy Pattern
    • Intents
    06/02/09 Devpia A&D EVA satellite Super Computer Do you think that the same logic use between satellite and super computer?
  • Strategy 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;
    • }
    06/02/09 Devpia A&D EVA CSort +Sorting() CBubble +Sorting() CQuick +Sorting()
  • Template Method Pattern
    • Intents
    06/02/09 Devpia A&D EVA ODBC(JDBC) API Application ODBC (JDBC) Driver Manager MSSQL Driver Oracle Driver
  • Template Method Pattern in GoF 06/02/09 Devpia A&D EVA 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; } CQueryTemplate +doQuery() #FormatConnect() #FormatSelect() COracleQT #FormatConnect() #FormatSelect() CSqlSvrQT #FormatConnect() #FormatSelect() Inversion of Control (Hollywood Principle)
  • Component Configurator Pattern
    • Intents
    06/02/09 Devpia A&D EVA Configuration File HTTP Protocol Text Based Log Component DES RSA XML Based Log Component FTP Protocol When Change Config File Info , Component Configuration (Attribute) dynamically Changes ! Great Architect
  • Component Configurator in POSA2 06/02/09 Devpia A&D EVA Component +Init() +Fini() +Suspend() +Resume() +Info() Core Component Core Component Component Repository Component Configurator
  • Component Configurator in POSA2 06/02/09 Devpia A&D EVA
  • Component 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;
    • }
    06/02/09 Devpia A&D EVA Advanced Topic Reflection
  • Component Configurator Example
    • App.config/Web.config
    In App.config. <?xml version=&quot;1.0“ encoding=&quot;utf-8&quot; ?> <configuration>      <appSettings>         <add key=&quot;sqlCon&quot; value=&quot; 컨넥션 스트링 정의 &quot;/>      </appSettings> </configuration>  In C# Code. System.Configuration.ConfigurationSetings.AppSetting[“sqlCon”];
  • Reflection Pattern in POSA1 Component A UserInterface MetaObject A MetaObject B MOP Meta Level Base Level Component B uses uses uses uses modifies modifies provides access to further base-level components further meta-level components retrieves information
  • Reflection ModuleBuilder AssemblyModule = CreatedAssembly.DefineDynamicModule(&quot;MathModule&quot;,&quot;Math.dll&quot;); TypeBuilder MathType = AssemblyModule.DefineType(&quot;DoMath&quot;, TypeAttributes.Public | TypeAttributes.Class); System.Type [] ParamTypes = new Type[] {typeof(int),typeof(int) }; MethodBuilder SumMethod = MathType.DefineMethod(&quot;Sum&quot;, MethodAttributes.Public, typeof(int), ParamTypes); ParameterBuilder Param1 = SumMethod.DefineParameter(1,ParameterAttributes.In, &quot;num1&quot;); ParameterBuilder Param2 = SumMethod.DefineParameter(1,ParameterAttributes.In, &quot;num2&quot;); . . . MathType.CreateType(); return CreatedAssembly;
  • Reflection using System; using System.Reflection; ... public class EmitDemoTest { static void Main() { ... System.Type MathType = EmitAssembly.GetType(&quot;DoMath&quot;); object[] Parameters = new object [2]; Parameters[0] = (object) (5); Parameters[1] = (object) (9); object EmitObj = Activator.CreateInstance (MathType,false); object Result = MathType.InvokeMember(&quot;Sum&quot;, BindingFlags.InvokeMethod ,null,EmitObj,Parameters); Console.WriteLine(&quot;Sum of {0}+{1} is {2}&quot;, Parameters[0],Parameters[1],Result.ToString()); Console.ReadLine(); } }
  • Pipe & Filter Pattern in POSA1 Protocol Handler InputOutput Handler component->svc() io->receive_data() Filter::svc() parse() Filter::svc() perform() Filter::svc() log() pipe io component Protocol Pipeline svc() Read Request svc() Filter svc() Filter svc() parse() Parse Headers svc() parse() Perform Request svc() perform() Log Request svc() log()
  • Using Pipeline Perform Request Log Request 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 Read Request GET /~jxh/hoem.html HTTP/1.0 Connection: Keep-Alive User-Agent: Mothra/0.1 Host: any.net Accept: image/gif, image/jpeg, */* Parse Request GET /users/jxh/public_thml/home.html HTTP /1.0 Parse Headers CONNECTION USER_AGENT HOST ACCEPT ACCEPT ACCEPT Keep-Alive Mothra/0.1 any.net image/gif image/jpeg */*
  • Pipe & Filter in WCF Services Runtime Layer Messaging Layer Behaviors Channels Instancing Behavior Security Channel TCP Transport Channel UDP Transport Channel Cross-Proc Transport Channel Queue Transport Channel HTTP Transport Channel Full Duplex Channel Reliable Messaging Channel Custom Channel Transaction Behavior CLR Type Integration Behavior Throttling Behavior Metadata Behavior Error Handling Behavior Concurrency Behavior Custom Behavior Security Channel HTTP Transport Channel TCP Transport Channel UDP Transport Channel Reliable Messaging Channel Custom Channel Instancing Behavior Custom Behavior Contract To Type Behavior
  • Factory Pattern
    • Intents
    06/02/09 Devpia A&D EVA Main Function Based Coding Object Oriented Programming
  • Factory Pattern (Abstract Factory)
    • Intents
    06/02/09 Devpia A&D EVA OO Design Advanced OO Design
  • Factory Pattern in GOF 06/02/09 Devpia A&D EVA 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; } Abstract Factory +CrateProduct() Client Concrete Factory Abstract Product Concrete Product
  • Factory Pattern in GOF 06/02/09 Devpia A&D EVA 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; } } Abstract Factory +CrateProduct() Client Concrete Factory Abstract Product Concrete Product Reminds Component Configurator!!
  • 3 Foe Patterns 06/02/09 Devpia A&D EVA Configurable Part Variable Part Common Part (Modularity) Log Security Transaction Component Configurator Factory Strategy <<LINKS>> <<CREATES>>
  • Observer Pattern (Misconception) 06/02/09 Devpia A&D EVA Change Data Misconception!! Or Prejudices ( 편견 !) 1. Observation 2. Notification
  • Observer is Notifieer!! 06/02/09 Devpia A&D EVA Observer in Observer Pattern is Notifieer
  • Hollywood Principle 06/02/09 Devpia A&D EVA Applicants Manager Don’t Call us!!
  • Hollywood Principle 06/02/09 Devpia A&D EVA Applicants Manager Don’t Call us! We Call You!!!
  • Flow of Observer Pattern 06/02/09 Devpia A&D EVA Data Client (Type1) Client (Type2) Client (Type3) Manager Client (Source) Observer is Notifieer Change 1. Change 2. Change 3. Notification
  • Observer Pattern in GoF 06/02/09 Devpia A&D EVA Subject +Attach (Observer o) +Detach (Observer o) +Notify() Concrete Subject Observer +Update () Concrete Observer
  • Publisher-Subscriber Replication DB Publisher Change DB Subscriber DB Subscriber DB Subscriber Reference Reference Reference
  • With Today’s Patterns Configuration File App.config Web.config Client A Client B Overhead!! File I/O Load Get Info Change Config File Notifiy Handler
  • With Today’s Patterns Configuration File App.config Web.config Client A Load Get Info Change Config File Notifiy FileSystemWatcher .NotifyFilter Handler A Smart Developer
  • Chain of Responsibility
    • Intents
    06/02/09 Devpia A&D EVA
  • Chain of Responsibility
    • The Last Solution
      • 바퀴벌레 팩
        • http://ajujoa.com/2460506
    06/02/09 Devpia A&D EVA
  • Chain of Responsibility in GoF 06/02/09 Devpia A&D EVA +successor Client Handler +HandleRequest() Concrete Handler
  • Chain Of Responsibilty (cont’d)
    • Design Strategy
      • The First Handler
        • Consider Probability
        • In order of Frequency of Use,
        • Consist of Handler Sequences
      • Role of The Last Handler
        • My Parents
        • Solve every problems!
    • Known Use
      • Exception Handling Mechanism
    06/02/09 Devpia A&D EVA
  • Review
    • Strategy
      • Support Algorithm that Context Considers
    • Template Method
      • Strategy Pattern + Template
    • Component Configurator & Reflection
      • Metadata Based Programming
    • Pipe & Filter Pattern
      • Support Plug-in Functionality
    • Observer
      • Inversion of Control (IoC)
    • Chain of Responsibility
      • Exception Handling Mechanism
    06/02/09 Devpia A&D EVA
  • Pattern Explore
  • How to Study Pattern? 06/02/09 Devpia A&D EVA
  • Architectural Pattern (POSA1)
      • Layer
      • Pipe & Filter
      • Broker
      • Master Slave
      • Client – Dispatcher
      • Forwarder-Receiver
      • Model – View
      • Controller
      • Presentation –Abstraction - Control
      • Reflection
      • Counted Pointer
      • Blackboard
    06/02/09 Devpia A&D EVA
  • Patterns For Concurrent & Networked Object (POSA2) 06/02/09 Devpia A&D EVA
  • Patterns for Resource Management (POSA3)
    • Resource Acquisition
      • Lookup
      • Lazy Acquisition
      • Eager Acquisition
      • Partial Acquisition
    • Resource Lifecycle
      • Caching
      • Pooling
      • Coordinator
      • Resource Lifecycle Manager
    • Resource Release
      • Leasing
      • Evictor
    06/02/09 Devpia A&D EVA
  • Refactoring & Anti-Patterns 06/02/09 Devpia A&D EVA
  • Various Patterns 06/02/09 Devpia A&D EVA
  • Various Patterns 06/02/09 Devpia A&D EVA
  • References
    • Frank Buschmann et al, “ Pattern-Oriented Software Architecture : A System of Patterns ”, Volume 1, Wiley
    • Douglas Schmidt et al, “ Pattern-Oriented Software Architecture ”, Volume 2, Wiley
    • Eric Gamma et al, “ Design Patterns : Elements of Reusable Object Oriented Software ” , Addison Wesley
    • Pipe & Filter Pattern, http://www.codeproject.com/cs/design/PipesAndFilters.asp
    • Reflection Pattern, http://www.codeproject.com/csharp/introreflection.asp
  • References
    • FileSystemWatcher.NotifyFilter
    • http://msdn2.microsoft.com/en-us/library/system.io.filesystemwatcher.notifyfilter(VS.80).aspx
    • Pattern Explore
    • http://www.codeplex.com/Wiki/View.aspx?ProjectName=guidanceExplorer
    • Devpia A&D Free Online Lecture
    • http://www.devpia.com/NewStudy/LectureList.aspx?ClassA=A&ClassB=05&ClassC=01
  • Questions
    • Give me Question
    • about Patterns!!
    • Devpia Architecture & Design Q&A http://www.devpia.com/Maeul/Contents/List.aspx?BoardID=4&MAEULNo=4
    06/02/09 Devpia A&D EVA