˘ˇ ˆˆ ˙ ˝ ˙ ˛ ˚ ˆ˜rkj/talks/patternslectures.pdf · copy self #˘ %ˇ client operation...
Post on 20-Jul-2020
13 Views
Preview:
TRANSCRIPT
���������������� ����
�������������
��������� ������ ��������������������������
��������������������������� !��"��
#��"��$ %&&&'(
������������������������
� �������������)����������������*�����)��������
� �������������"��������������������������+
� �������������"������������,"����- ,��"�����-
�.����"����������������������������������/����������0
���������������������������
���������������� �������������
�����������*����"�������12��3�����45''
26��������������12��3���������45''
�7�����������������"��������������������������������������"������������������������������"������������������
��3������1������������ ��8�������������������� ��"�������������� ��������*����*�
���������������������������
�����������������������������������������*�������������������������������������� ���"��������������
� �������������9"/���9�����������*����������������*�������������������������"������������������������������������������"�������������������������������������
��!����������"����
�:����*�������������������;�#<�*����)����"����=&;�
�!�������������*��������������������������������������*��������������������������������������������*���
� ������������6���;�����"�����#<������*���>45==?
� ��������������;�����"���17�� ��*������������������������������>455@?
#���$�������������������!!���%�
� A����������"��������������BB�����*��������6� ��������455@
� 6����������"�������������������������������������������2�#��455@
� ����������C��996�D2*��������������������455@���455E
� �������������"�������������������"����������������
� �������������������)�"������������*����������99����*������������
�����"��!
������������������ "��������������"/��� �������"�����������������������"/���9"�����������������3�������"/���������������������"�������$����������������
.�������)�����������������������)��������"��� ������������������*����)������������������������
copy self
#����������
Client
operation ()
ShapePrototype
clone ()
CirclePrototype
clone ()
RectanglePrototype
clone ()
proto
proto-->clone()
copy self
copy self
#�����������������������%��
Client
operation ()
Prototype
clone ()
ConcretePrototype1
clone ()
ConcretePrototype2
clone ()
proto
proto-->clone()
copy self
���&�"����������������
���������������������"������������)��
�#���)���������������������������*���������������3�����
�6��)����������������������������
� �����������"��������"��*����������
� �����������������������������������������������$���� ��������������������8������
�����������&������#�!������
��� ����"%���&��$�!!����'����
���������� �����������������
����� ��������� �������������
�������� ���������� ��������������
������������� ������������� ������������ �
�����������
��������������
������&����������������
�����������6�������
� ����������"���*�������������*�"/����
�����������6�������
� ����������"��������������������"/��������������
�!���)�����6�������
� ����������"���*�����*�����"/������������
������������������
����������
� �����������������������������
�6��������
� ���������"/����"���������3�������"/����
�!������
� "�������"/��������3��������������������
������������������
�:������#�����
� ����������������������"�������
�2"������:������
� 6��)��������������������������������"/����*����������������������������������������"/����
���������&����������&����������%����������&���������!���
Singleton
static getSoleInstance()operation ()
static soleInstancedata
..return soleInstance
(!���!������������
�#��������������������������
� 6����"��������������������
�2��*���������������"���������������������������
�����������������������������������������
� ������������8����������������
�������'&
��������������F
���������1
���������>?+
��"���1
���������������G���������������>?FHI+
���)���1
���������������G������������+
I
�&���%�)�����
�3�����12�����*����������������������������������*������"���������������������*������������ �����������������������)�����*�������������� ���3����������������������
2��"����������������������1��������������������������� ������� ���� �������>? ����� �������
�����������������������������)���������������
����� ����� ��������������� �������������� �������
����� ������������� �������
Return new GraphicDocument
������!������� �&���%�)�����
Document
open(), close()save () ..
ApplicationcreateDoc ()newDoc ()openDoc()
GraphicDrawingApl
createDoc()
Document *d=createDocdocs.add(d);
GraphicDocument
docs
Return new ConcreteCreator
#��� �&���%�)�������������
Product CreatorfactoryMethod()
operation ()
GraphicDrawingApl
factoryMethod()
Product= factoryMethod()
concreteProduct
����&��������������
�2������
� ���)�����������������������
����������
� ��������"/��������������������
� ��������
� 2�����������������������"������������������
)��������&��������������
�6��3�
� 6��)�������������������������������������"/���
�:�����
� 6��)�������������������������������������������"������
�!�����
� ��������"��������������������������� �������)����������������
���������������
�J�����"����������������������������������������������������:�:9 ��� D�:9
�J��������������������3����������������*�������"�����������)�����D�:9����������
�7�*��*����������3������������������*����������������������������0
#����������
Client Collectioninsert ()fetch ()
Stackpush()pop ()
LIFO
insert ()fetch ()
pop ()
FIFO
insert ()fetch ()
#������������������
�����������
Client Target
request ()
Adaptee
specificReq ()
Adapter
request ()
specificReq()
#������������������
� ��������
Client Target
request ()
Adaptee
specificReq ()
Adapter
request ()
adaptee->specifiReq()
adaptee
��!�������������
�2��3�����12A������ �����������������������������"/����������D��� ��������� ������ ��3� ��������������A�������� �������
�������������������������������������������������
#����������
Client GraphicElement
draw ()add () ..
Circle
draw ()
GraphicDocdraw()add (..)
For all g in GEsg->draw()
Line
draw ()GEs
(�����&������&������������(�����&�����
����!�����������
myPicture
hasPicture aSquare aText
aLine aRectangle
#�����!�������������
Client Component
operation ()
Composite
operation()add (..)
For all c in childrenc->operation()
aLeaf
operation ()
children
*�����������&������&�!��������
���������"�%���!+
�������������*�����������
#��� �&�����������
6��)��������������������������"������
Facade
�������!�������!���
� �����"�����������������$ ���������*��������������"������������������)��
�D�������������������$ ���������*������������������������)��
�2��������)����������������"/������������������"/���
��� �!���������)������������������������������������
���������������,"-�&��
ClientProg Account
deposit ()
AccountProxy
deposit ()
remoteAcc->deposit
RealAccount
deposit ()
remoteAcc
#�������%��������
Client subject
operation ()
Proxy
operation()
realSubj->operation
RealSubject
operation ()
realSubj
#�������%
�!�������������3��"/������������������"����������������
����� ����"������)�������������������
���������������������������������
�2������������������������������������������C����� ��������������������
��������������3���������������������������*�������������"/���
#����������
�������������������������"/���
���"/���������"����������������
� ������"/�����������)����������������
�6��3���������3����������������)����"��������������������
�6��3�������������������"/���
����������>?���������������������������"�������"/������6��3��������
#�����&��������,"-�&������!
borderDecorator
scrollDecoratortextView
client
componentcomponent
����!���.
server
dec1
dec2
client
����!���/
server
Abstractdec
dec1
client
dec2
����!���0
server
dec
dec1client dec2
����!���1
server
dec
dec1client dec2
Visualcomponent
draw ()
Decorator
draw()Component->draw()
TextView
operation ()
Borderdraw()
drawBorder()
Scrollerdraw ()
drawScroller
component
Decorator::draw()drawBorder()
2��� �������������
���������#�����
� D���������������������������"��������"������"�����
���������
� �����������������������������������������������������"��
���������
� ���)�������������������������)����������������������������
)����2��� �������������
�9"���)��
� ������"/��������������� ����������������"����������������������
������
� 2���*���"/�������������"���)���*��������������������
��������*����&�%�
#�!������)�����
Shape
move(Point to)draw(Color c)
Circle
draw (..)
Draw (0);current=to;draw (1);
#���#�!������)�������������
AbstractClass
templateMethod()primitiveMethod
ConcreteClass
primitiveMethod()
….primitiveMethod
….
����"-�&������������"��� ��������
&�����������������������������
�3�����12��6�����������"/������)���������������������>? �����>? ����>?��������������"/�������������"���)�������������������������������������������������������������� ���������"����������
#����������������������������������
TCPConnectionopen ()
close ()..
TCPState
open ()close () ..
Listening
open ()close ()
Closedopen ()close ()
State->open ()
Established
open ()close ()
state
#����������������
Context
request ()
State
handle ()
ConcreteState2d
handle ()
state->handle ()
ConcreteState1
handle ()
state
3������������������!��������������
�!����������%��������
�3�����12����������������������3�<����������"��������������������"����������������������������"�������������
���������"��������������������#�������������1�������������"����� ��������������
�����������1��������������������������������
������������1������*������3�����"�����������
#����������
Document
format ()
Compositor
compose ()
SimpleCompositor
simpleCompose()
arrayCompositor
arrayCompose ()
compositor->compose ()
paraCompositor
paraCompose()
compositor
#���������%��������
Context
aMethod ()
Strategy
algorithm ()
ConcreteStrategy1
algorithm1()
ConcreteStrategy3
Algorithm3 ()
strat->algorithm ()
ConcreteStrategy2
algorithm2 ()
strat
�������&��
K4L�A���� �7��� �������� �<�������� �����6������� 2������$.����� 455M
K@L.6��� �����6����������9"/���$9������� �)�������� 2������$.����� 455M
KELD���������� ���6�������7���"��� ���"�����N��)������6���� 455=
top related