54
!" #" $ %&&&’(

˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

  • Upload
    others

  • View
    23

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

���������������� ����

�������������

��������� ������ ��������������������������

��������������������������� !��"��

#��"��$ %&&&'(

Page 2: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

������������������������

� �������������)����������������*�����)��������

� �������������"��������������������������+

� �������������"������������,"����- ,��"�����-

�.����"����������������������������������/����������0

Page 3: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

���������������������������

���������������� �������������

�����������*����"�������12��3�����45''

26��������������12��3���������45''

�7�����������������"��������������������������������������"������������������������������"������������������

��3������1������������ ��8�������������������� ��"�������������� ��������*����*�

Page 4: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

���������������������������

�����������������������������������������*�������������������������������������� ���"��������������

� �������������9"/���9�����������*����������������*�������������������������"������������������������������������������"�������������������������������������

Page 5: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

��!����������"����

�:����*�������������������;�#<�*����)����"����=&;�

�!�������������*��������������������������������������*��������������������������������������������*���

� ������������6���;�����"�����#<������*���>45==?

� ��������������;�����"���17�� ��*������������������������������>455@?

Page 6: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#���$�������������������!!���%�

� A����������"��������������BB�����*��������6� ��������455@

� 6����������"�������������������������������������������2�#��455@

� ����������C��996�D2*��������������������455@���455E

� �������������"�������������������"����������������

� �������������������)�"������������*����������99����*������������

Page 7: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

�����"��!

������������������ "��������������"/��� �������"�����������������������"/���9"�����������������3�������"/���������������������"�������$����������������

.�������)�����������������������)��������"��� ������������������*����)������������������������

Page 8: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

copy self

#����������

Client

operation ()

ShapePrototype

clone ()

CirclePrototype

clone ()

RectanglePrototype

clone ()

proto

proto-->clone()

copy self

Page 9: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

copy self

#�����������������������%��

Client

operation ()

Prototype

clone ()

ConcretePrototype1

clone ()

ConcretePrototype2

clone ()

proto

proto-->clone()

copy self

Page 10: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

���&�"����������������

���������������������"������������)��

�#���)���������������������������*���������������3�����

�6��)����������������������������

� �����������"��������"��*����������

� �����������������������������������������������$���� ��������������������8������

Page 11: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

�����������&������#�!������

��� ����"%���&��$�!!����'����

���������� �����������������

����� ��������� �������������

�������� ���������� ��������������

������������� ������������� ������������ �

�����������

��������������

Page 12: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

������&����������������

�����������6�������

� ����������"���*�������������*�"/����

�����������6�������

� ����������"��������������������"/��������������

�!���)�����6�������

� ����������"���*�����*�����"/������������

Page 13: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

������������������

����������

� �����������������������������

�6��������

� ���������"/����"���������3�������"/����

�!������

� "�������"/��������3��������������������

Page 14: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

������������������

�:������#�����

� ����������������������"�������

�2"������:������

� 6��)��������������������������������"/����*����������������������������������������"/����

Page 15: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

���������&����������&����������%����������&���������!���

Singleton

static getSoleInstance()operation ()

static soleInstancedata

..return soleInstance

Page 16: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

(!���!������������

�#��������������������������

� 6����"��������������������

�2��*���������������"���������������������������

�����������������������������������������

� ������������8����������������

Page 17: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

�������'&

��������������F

���������1

���������>?+

��"���1

���������������G���������������>?FHI+

���)���1

���������������G������������+

I

Page 18: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

�&���%�)�����

�3�����12�����*����������������������������������*������"���������������������*������������ �����������������������)�����*�������������� ���3����������������������

2��"����������������������1��������������������������� ������� ���� �������>? ����� �������

�����������������������������)���������������

����� ����� ��������������� �������������� �������

����� ������������� �������

Page 19: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

Return new GraphicDocument

������!������� �&���%�)�����

Document

open(), close()save () ..

ApplicationcreateDoc ()newDoc ()openDoc()

GraphicDrawingApl

createDoc()

Document *d=createDocdocs.add(d);

GraphicDocument

docs

Page 20: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

Return new ConcreteCreator

#��� �&���%�)�������������

Product CreatorfactoryMethod()

operation ()

GraphicDrawingApl

factoryMethod()

Product= factoryMethod()

concreteProduct

Page 21: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

����&��������������

�2������

� ���)�����������������������

����������

� ��������"/��������������������

� ��������

� 2�����������������������"������������������

Page 22: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

)��������&��������������

�6��3�

� 6��)�������������������������������������"/���

�:�����

� 6��)�������������������������������������������"������

�!�����

� ��������"��������������������������� �������)����������������

Page 23: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

���������������

�J�����"����������������������������������������������������:�:9 ��� D�:9

�J��������������������3����������������*�������"�����������)�����D�:9����������

�7�*��*����������3������������������*����������������������������0

Page 24: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#����������

Client Collectioninsert ()fetch ()

Stackpush()pop ()

LIFO

insert ()fetch ()

pop ()

FIFO

insert ()fetch ()

Page 25: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#������������������

�����������

Client Target

request ()

Adaptee

specificReq ()

Adapter

request ()

specificReq()

Page 26: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#������������������

� ��������

Client Target

request ()

Adaptee

specificReq ()

Adapter

request ()

adaptee->specifiReq()

adaptee

Page 27: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

��!�������������

�2��3�����12A������ �����������������������������"/����������D��� ��������� ������ ��3� ��������������A�������� �������

�������������������������������������������������

Page 28: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#����������

Client GraphicElement

draw ()add () ..

Circle

draw ()

GraphicDocdraw()add (..)

For all g in GEsg->draw()

Line

draw ()GEs

Page 29: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

(�����&������&������������(�����&�����

����!�����������

myPicture

hasPicture aSquare aText

aLine aRectangle

Page 30: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#�����!�������������

Client Component

operation ()

Composite

operation()add (..)

For all c in childrenc->operation()

aLeaf

operation ()

children

Page 31: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

*�����������&������&�!��������

���������"�%���!+

�������������*�����������

Page 32: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#��� �&�����������

6��)��������������������������"������

Facade

Page 33: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

�������!�������!���

� �����"�����������������$ ���������*��������������"������������������)��

�D�������������������$ ���������*������������������������)��

�2��������)����������������"/������������������"/���

��� �!���������)������������������������������������

Page 34: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

���������������,"-�&��

ClientProg Account

deposit ()

AccountProxy

deposit ()

remoteAcc->deposit

RealAccount

deposit ()

remoteAcc

Page 35: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#�������%��������

Client subject

operation ()

Proxy

operation()

realSubj->operation

RealSubject

operation ()

realSubj

Page 36: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#�������%

�!�������������3��"/������������������"����������������

����� ����"������)�������������������

���������������������������������

�2������������������������������������������C����� ��������������������

��������������3���������������������������*�������������"/���

Page 37: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#����������

�������������������������"/���

���"/���������"����������������

� ������"/�����������)����������������

�6��3���������3����������������)����"��������������������

�6��3�������������������"/���

����������>?���������������������������"�������"/������6��3��������

Page 38: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#�����&��������,"-�&������!

borderDecorator

scrollDecoratortextView

client

componentcomponent

Page 39: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

����!���.

server

dec1

dec2

client

Page 40: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

����!���/

server

Abstractdec

dec1

client

dec2

Page 41: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

����!���0

server

dec

dec1client dec2

Page 42: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

����!���1

server

dec

dec1client dec2

Page 43: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

Visualcomponent

draw ()

Decorator

draw()Component->draw()

TextView

operation ()

Borderdraw()

drawBorder()

Scrollerdraw ()

drawScroller

component

Decorator::draw()drawBorder()

Page 44: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

2��� �������������

���������#�����

� D���������������������������"��������"������"�����

���������

� �����������������������������������������������������"��

���������

� ���)�������������������������)����������������������������

Page 45: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

)����2��� �������������

�9"���)��

� ������"/��������������� ����������������"����������������������

������

� 2���*���"/�������������"���)���*��������������������

Page 46: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

��������*����&�%�

#�!������)�����

Shape

move(Point to)draw(Color c)

Circle

draw (..)

Draw (0);current=to;draw (1);

Page 47: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#���#�!������)�������������

AbstractClass

templateMethod()primitiveMethod

ConcreteClass

primitiveMethod()

….primitiveMethod

….

Page 48: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

����"-�&������������"��� ��������

&�����������������������������

�3�����12��6�����������"/������)���������������������>? �����>? ����>?��������������"/�������������"���)�������������������������������������������������������������� ���������"����������

Page 49: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#����������������������������������

TCPConnectionopen ()

close ()..

TCPState

open ()close () ..

Listening

open ()close ()

Closedopen ()close ()

State->open ()

Established

open ()close ()

state

Page 50: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#����������������

Context

request ()

State

handle ()

ConcreteState2d

handle ()

state->handle ()

ConcreteState1

handle ()

state

Page 51: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

3������������������!��������������

�!����������%��������

�3�����12����������������������3�<����������"��������������������"����������������������������"�������������

���������"��������������������#�������������1�������������"����� ��������������

�����������1��������������������������������

������������1������*������3�����"�����������

Page 52: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#����������

Document

format ()

Compositor

compose ()

SimpleCompositor

simpleCompose()

arrayCompositor

arrayCompose ()

compositor->compose ()

paraCompositor

paraCompose()

compositor

Page 53: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

#���������%��������

Context

aMethod ()

Strategy

algorithm ()

ConcreteStrategy1

algorithm1()

ConcreteStrategy3

Algorithm3 ()

strat->algorithm ()

ConcreteStrategy2

algorithm2 ()

strat

Page 54: ˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ Client operation Prototype clone ConcretePrototype1 clone () ConcretePrototype2 clone () proto proto-->clone()

�������&��

K4L�A���� �7��� �������� �<�������� �����6������� 2������$.����� 455M

[email protected]��� �����6����������9"/���$9������� �)�������� 2������$.����� 455M

KELD���������� ���6�������7���"��� ���"�����N��)������6���� 455=