?e??d?????e? ?????a - PowerPoint PPT Presentation

About This Presentation
Title:

?e??d?????e? ?????a

Description:

Title: PowerPoint Presentation Author: Emil Vassev Last modified by: studin Created Date: 5/4/2003 5:24:40 PM Document presentation format: ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 47
Provided by: Emil192
Category:
Tags: emil

less

Transcript and Presenter's Notes

Title: ?e??d?????e? ?????a


1
?e??d?????e? ?????aµµat?sµ?? ??
S?ed?ast??? ???t?pa (1)
?a?a???t?? Sf?ts??, PhD http//aetos.it.teithe.gr/
sfetsos/ sfetsos_at_it.teithe.gr
2
St????
  • Ge???? ??a ta ???t?pa
  • S?ed?ast??? ???t?pa
  • ?atas?e?ast??? (Creational)
  • ??µ??? (Structural)
  • S?µpe??f????? (Behavioral)

3
S?ed?ast??? ???t?pa
?p? t?? ????te?t?????
Christopher Alexander ????t??t??a?,
1979 ??a?????s? ?????? ?a?a?t???st???? se s??d?a
?a??? p???t?ta? ? a?????... ?????? ??se?? se
????? ???ß??µata ??a pa?a???? s?ed??? ?a???
p???t?ta?
4
S?ed?ast??? ???t?pa
St? ????sµ???
????? '90. ?p?????? p??ß??µata st? ????sµ???
ta ?p??a epa?a?aµß????ta? ?p???e? ? d??at?t?ta
s?ed?as?? ????sµ???? µe p??t?pa ?? Gamma, Helm,
Johnson ?a? Vlissides (Gang of Four -
GoF) ap??t?sa? ???.
5
S?ed?ast??? ???t?pa
???sµ??
  • ??a p??t?p? pe?????fe? ??a epa?a?aµßa??µe??
    p??ß??µa, se
  • ??a s???e???µ??? pe??ß?????, ?a? µ?a ?a??
    te?µ????µ??? ??s?
  • t??.
  • S???pe?e?
  • ?pa?a???s?µ?p???s? s?ed???
  • ?pa?a???s?µ?p???s? ??d??a
  • ??a?e???s? a??a???
  • ?? GoF ?at??t?sa? ??a? ?at????? µe 23 p??t?pa
    s?ed?as??.

6
?e????af? t?? ???t?p??
? ?at?????? t?? ?a?a?t???st???? t?? p??t?p?? GoF
7
S?ed?ast??? ???t?pa
?a???e? S?ed?as?? µe ta ???t?pa
  • S?ed?????µe µe d?as??d?se?? (d?epaf?? ?
    af???µ??e? ???se??)
  • ???t?µ??µe t?? s???es? (composition) ap? t??
  • ???????µ???t?ta (inheritance)
  • ???s???µe t? a????e? ?a? t? e????a?????µe
    (encapsulate)

8
S?ed?ast??? ???t?pa
St???e?a t?? p??t?p??
?at?????e? ?atas?e?ast??? (Creational)
?s??????ta? µe t?? d?e??as?e? d?µ??????a? t??
a?t??e?µ???? ??µ??? (Structural) ?s??????ta? µe
t?? d?e??as?e? s???es?? t?? ???se??/a?t??e?µ????
S?µpe??f????? (Behavioral) ?s??????ta? µe t???
t??p??? µe t??? ?p????? ?? ???se?? a????ep?d????
?a? ?ata??µ??? t?? a?µ?d??t?te?
9
Strategy (St?at?????) 1/6
?at?????a Behavioral S??p?? ?? p??t?p? a?t?
????e? ?a? e?s?µat??e? µ?a ???????e?a a??????µ??
(sa? a?t??e?µe?a) ep?t??p??ta? ta?t?????a ?a?
t?? e?a??a?t??? e?t??es? t??. ?p?t??pe? t?
µetaß??? t?? a??????µ??, a?e???t?ta ap? t???
pe??te? p?? t??? ???s?µ?p?????. S?????µa -
10
Strategy (St?at?????) 2/6
  • ???s?µ?p??e?ta? st?? pe??pt?se?? ???p???s??
    e??? ??????
  • ?e????? a??????µ?? (p.?. ta????µ?s?) a???
    ?a? p?????
  • d?af???p???se?? t?? (p.?. f?sa??da?,
    e?sa????? ?.t.?.).
  • ??t??e? s?µpe??f???? e??a? s????? st??
    a?t??e?µe??st?ef?
  • p????aµµat?sµ? ?a? pa?ap?µp??? s?????? st??
    ?????-
  • ??µ???t?ta. ?? p??t?p? St?at?????
    a?t?µet?p??e? t?t??a
  • p??ß??µata st?????µe?? ??? µ??? st??
    ???????µ???t?ta,
  • a??? ?a? st? s???es? a?t??e?µ????.
  • ?fa?µ??e? t?? a??? t?? ??t?st??f?? t??
    ??a?t?se??
  • a?a??????ta? t?? ?e???? a??????µ? ?a? t??
    ?ept?µe?e??
  • ???p???se?? ?a e?a?t??ta? ap? afa???se??.

11
Strategy (St?at?????) 3/6
  • ???s?
  • ?ta? ????µe s?s?et???µe?e? ???se?? p??
    d?af????? µ??? ??
  • p??? t?? s?µpe??f???.
  • ?a???e? se µ?a ???s? t? d??at?t?ta ?a e?te?e?
    µ?a ap? p?????
  • s?µpe??f????.
  • ?ta? ?p?????? p????? pa?a??a??? t?? ?d???
    a??????µ??. ???e
  • pa?a??a?? e?s?µat??eta? se ??p??a
    St?at?????.
  • ??a ???s? ????e? p????? s?µpe??f???? p??
    ep??????ta? ap?
  • p???ap??? e?t???? s??????? t?? ?p??e?
    µp????µe ?a
  • e?a??st?p???s??µe µe e?s?µ?t?s? t??? se
    st?at??????.

12
Strategy (St?at?????) 4/6
??af??et???? a??????µ?? ???p?????ta? sa?
s???e???µ??e? ?p????se?? t?? d?as??des?? Strategy
(d?epaf?? ? af???µ???? ???s??).
13
Strategy (St?at?????) 5/6
interface FortuneCookies public void
print() class Six implements FortuneCookies
public void print()
System.out.println("6-Exi") class Five
implements FortuneCookies public void print()
System.out.println("5-Pente") class
Four implements FortuneCookies public void
print() System.out.println("4-Tessera")
class Three implements FortuneCookies
public void print() System.out.println(
"3-Tria") class Two implements FortuneCookies
public void print()
System.out.println("2-Dyo") class One
implements FortuneCookies public void print()
System.out.println("1-Ena") class
Null implements FortuneCookies public void
print() System.out.println("Tipote")
? d?epaf? ?? ???se?? t?? a??????µ??


14
Strategy (St?at?????) 6/6
class Dice public int throwIt() return
(int)(Math.random()6)1 class strategyTest
static void goodFortune() int luckyNum
new Dice().throwIt() FortuneCookies fc.
switch (luckyNum) case 6 fc new
Six()break //d?µ??????a a?t??. case 5
fc new Five()break case 4 fc new
Four()break case 3 fc new
Three()break case 2 fc new
Two()break case 1 fc new
One()break default fc new
Null() fc.print() // e?t??es?
public static void main(String
args) goodFortune()
15
Singleton (???ad?a??) 1/3
  • ?at?????a Creational
  • S??p??
  • ???a? t? p??t?p? p?? ???s?µ?p??e?ta? ?ta? ?????µe
    ?a
  • e?asfa??s??µe ?t? µ?a ???s? ?a ??e? µ??? ??a
    st??µ??t?p?
  • ?a? ?t? ?a pa???e? ??a ?a?????? s?µe?? p??sßas??
    se a?t?.
  • S?????µa -

16
Singleton (???ad?a??) 2/3
  • ???a? ??a p??t?p? p?? ???s?µ?p????µe ?ta?
    ?????µe ?a d?µ??????s??µe
  • µ??? ??a a?t??e?µe?? se µ?a ???s?.
  • ? ????? t?? µ??ad?a??? a?t??e?µ???? e??a?
    s?????? ? d?a?e???s? t??
  • ?p????p?? a?t??e?µ???? t?? efa?µ????.
  • ?a µ??ad?a?a a?t??e?µe?a d?µ????????ta? ap? µ?a
    e?d??? µ???d? p??
  • - e????e? a? ??p??? a?t??e?µe?? ??e? ?d?
    d?µ???????e?. ?? ?a?, ?
  • µ???d?? ep?st??fe? ap??? ??a? de??t? p???
    t? ?p????? a?t??e?µe??.
  • ?? ???, ? µ???d?? d?µ?????e? ??a ???
    a?t??e?µe?? ?a? ep?st??fe?
  • de??t? p??? a?t?.
  • O ?atas?e?ast?? t?? ???s?? d????eta? ??
    p??state?µ???? (protected) ?
  • ?d??t???? (private) ??a ?a e?asfa??ste? ?t?
    ?a d?µ???????e? t? a?t??e?µe??
  • µ??? µ?s? a?t?? t?? µe??d??.

17
Singleton (???ad?a??) 3/3
  • St?? Java
  • public class Singleton
  • private static Singleton instance // ?
    instance null
  • / ????s? p??sßas?? st?? ?atas?e?ast? /
  • private Singleton() //d?µ?t?? µ??? ?
    Singleton µp??e? ?a t?? ???s?µ?p???se?
  • public static Singleton getInstance()
  • if (instance null)
  • instance new Singleton()
  • return instance

18
Adapter (???sa?µ???a?) 1/9
  • ?at?????a Structural
  • S??p??
  • ? µetat??p? t?? d?as??des?? µ?a? ???s?? se µ?a
    ???? (p??
  • a?aµ????? ta p?????µµata pe??te?). ?p?t??pe? se
    µ?
  • s?et???µe?e? ???se?? (as?µßate? d?as??d?se??) ?a
  • s???e?t?????s??? se ??a ????? p????aµµa.
  • S?????µa Wrapper (ed?pe??t????µa a?t??e?µ????)
  • ??? ?at?????e? p??sa?µ??e?? a?t??e?µ????
    (object adapters)
  • ?a? p??sa?µ??e?? ???se?? (class adapters).

19
Adapter (???sa?µ???a?) 2/9
  • ??µ?
  • ? p??sa?µ???a? ???s?? ???s?µ?p??e? t?? p???ap??
  • ???????µ???t?ta ??a ?a p??sa?µ?se? µ?a
    d?as??des?
  • se µ?a ????
  • ? p??sa?µ???a? a?t??e?µ???? ßas??eta? st??
    s???es?
  • a?t??e?µ???? (composition) ?a? d?aß?ßas?
    µ???µ?t??
  • (delegation)

20
Adapter (???sa?µ???a?) 3/9
?? s?µµet????te?...
Target ??as??des? p?? ???s?µ?p??e? ?
Client. Client ???s?µ?p??e? a?t??e?µe?a s?µf??a
µe t?? d?as??des? Target. Adaptee ? d?as??des?
p?? ??e???eta? p??sa?µ???. Adapter ???sa?µ??e?
t?? d?as??des? t?? Adaptee st? d?as??des? t??
Target.
21
Adapter (???sa?µ???a?) 4/9
???sa?µ??e?? ??t??e?µ???? (Object Adapters)
  • ? p??sa?µ???a? a?t??e?µ???? ßas??eta? st??
    s???es? a?t??e?µ????
  • composition) ?a? d?aß?ßas? µ???µ?t??
    (delegation).
  • ???????µe? t?? d?epaf? t?? Target p??
    ???s?µ?p??e? ? Client ?a? ?at??e?
  • ??a a?t??e?µe?? t?? Adaptee.
  • ?ta? ? Client ?a?e? t?? µ???d? request() µe t?
    a?t??e?µe??-Target, ? p??sa?µ???a?
  • t? µetaf???e? - p??sa?µ??e? st?
    specificRequest() t?? Adaptee (a?af???).
  • ? p??sa?µ???a? a?t??e?µ???? ep?t??pe? t??
    ???se?? Client ?a? Adaptee ?a e??a?
  • te?e??? as??dete?. ???? a?t?? ??????e? ?a?
    ??a t?? d??.

22
Adapter (???sa?µ???a?) 5/9
???sa?µ??e?? ??t??e?µ???? (Object Adapters)
class Target public void request() class
Adaptee public void specificRequest()
System.out.println("Adaptee SpecificRequest")
class Adapter extends Target private Adaptee
adaptee public Adapter(Adaptee a)
adaptee a public void request()
adaptee.specificRequest() class TestAdapter
public static void main(String args)
Adaptee a new Adaptee() Target t new
Adapter(a) t.request()
23
Adapter (???sa?µ???a?) 6/9
???sa?µ??e?? ???se?? (Class Adapters)
  • ? p??sa?µ???a? ???s?? ???s?µ?p??e? t?? p???ap??
    ???????µ???t?ta ??a ?a
  • p??sa?µ?se? µ?a d?as??des? se µ?a ????
  • ???????µe? t?? d?as??d?se?? t?? Target p??
    ???s?µ?p??e? ? Client ?a? t??
  • Adaptee.
  • St?? Java epe?d? de? ?p?st????eta? ? p???ap??
    ???????µ???t?ta ?a p??pe? µ?a
  • ap? t?? d?as??d?se?? ?a ???????µe?ta? ap?
    d?epaf? t?? Java. H target ?a?
  • ? Adaptee ?a µp????sa? ?a e??a? d?epaf??
    Java.
  • H request() st?? Target µetaf???eta?-p??sa?µ?
    ?eta? st?? specificRequest() p??
  • ???????µe?ta? ap? t?? ???s? Adaptee.

24
Adapter (???sa?µ???a?) 7/9
  • ?a??de??µa
  • Ta ???p???s??µe t??? p??sa?µ??e?? ???s?? ?a?
    a?t??e?µ???? p?? p??sa?µ????? t?? ???s? TextView
    ?ste ?a ta?????e? µe t?? d?as??des? t?? ???s??
    Shape.
  • ?? d?af???? st?? d?? a?t?? ???se?? e??a?
  • ?? ???t? p?a?s??? (? shape t? ????e? µe t??
    ap??a?t? ????e?, e?? ? TextView
  • µe t? ???? ?a? µ????).
  • ? Shape ????e? t?? µ???d? CreateManipulator()
    ??a ?a ?e????eta? t?? ????s?
  • (animation), e?? ? TextView de? ??e? a?t?st????
    µ???d?.
  • ? ???s? TextShape ?a e??a? ? p??sa?µ???a? µeta??
    a?t?? t?? d?af??et????
  • d?as??d?se??.

25
Adapter (???sa?µ???a?) 8/9
???p???s? µe ???sa?µ???a ???s??
  • ??????µe t?? TextShape ?a ???????µe? t??
    d?as??des? Shape ?a? t?? ???p???s?
  • (implementation) t?? TextView.
  • ???a??-?pe??????? (override) t?? µe??d??
    BoundingBox() µetat??p??ta? t??
  • d?as??des? t?? TextView ?ste ?a p??sa?µ?ste?
    st?? d?as??des? Shape.
  • ???a??-?pe???????
  • (override) t?? µe??d??
  • IsEmpty() ??a ?a
  • ste????µe t? µ???µa
  • ?ate??e?a? st??
  • IsEmpty() t?? TextView.
  • ???sµ?? t?? µe??d??
  • CreateManipulator() ap?
  • t?? a???.

26
Adapter (???sa?µ???a?) 9/9
???p???s? µe ???sa?µ???a ??t??e?µ????
  • ? ???sµ?? t?? TextShape ???p??e? ??a de??t? ??a
    t?? d?as??des? TextView.
  • ??????p??e? t?? de??t? st?? d?µ?t?.
  • ?a?e? µe??d??? µe t? a?t??e?µe?? t?? TextView
    p?? ?at??e?
  • ????e? t?? µ???d? CreateManipulator() ap? t??
    a??? (?p?? p???).

27
Bridge (G?f??a) 1/5
  • ?at?????a Structural
  • S??p??
  • ? ap?s??des? µ?a? afa??es?? ap? t?? ???p???s?
    t??, ?ste ?a? ta d?? ?a µp????? ?a µetaß?????ta?
    a?e???t?ta.
  • S?????µa Handle/Body

28
Bridge (G?f??a) 2/5
  • ?fa??es? ?a? ???p???s? s??d???ta? µ???µa,
    ?????ta?
  • d?s???? t?? ep??tas?, t??p?p???s? ?a?
    epa?a???s?µ?p???s?
  • t?? ??d??a.
  • ?µ?? µ?a afa??es? µp??e? ?a ??e? p?????
    ???p???se??
  • (?p????se?? p?? ???p????? t?? µe??d??? t??
    af???µ????
  • ???s??)
  • ?ta? µ?a afa??es? ??e? pe??ss?te?e? ap? µ?a
    ???p???se??, t?te
  • ???s?µ?p????µe ???????µ???t?ta.
  • ? G?f??a ???s?µ?p??e?ta? e?e? p?? s?µßa?????
    µetaß????
  • st?? afa??es? a??? ?a? st?? ???p???s? t??
    afa??es??.

29
Bridge (G?f??a) 3/5
  • ? afa??es? (Abstraction) s?ss?µat??e? µ?a
    ???p???s? (Implementor).
  • H ???s? RefinedAbstraction e??a? µ?a ep??tas?
    t?? afa??es??
  • ???s?µ?p????ta? ep?p???? µe??d??? ??a
    pe??ss?te?? ?e?t???????t?ta.
  • ? d?epaf? (Implementor) pa???e? µ?a d?epaf? ??a
    t?? ???se?? ???p???s??
  • (t?? ???se?? ConcreateImplementor)
  • H ???s? RefinedAbstraction af??? t?? afa??es?
    ?a? ??? t?? ???p???s?.
  • ??t? s?µa??e? ?t? ?ept?µ???e? t?? ???p???s??
    ???ß??ta? ap? t?? Client.

30
Bridge (G?f??a) 4/5

?a??de??µa To t??e???t??? t?? t??e??as?? (ap?
t? ß?ß??? Head First Design Patterns)
?e a?t? t?? ??s? ?p?st??????µe µetaß???? st??
???p???s? a??? ??? st?? afa??es?. ?? d????µa ??
?a ???e? ?ta? t? t??e???t??? a????e? ??s? Ta
s?ed??s??µe ?ts? ?ste ?a ?p?st???- ???µe
µetaß???? t?s? st?? ???p???s? ?s? ?a? st??
afa??es?.
31
Bridge (G?f??a) 5/5

???s?µ?p????µe to p??t?p? G?f??a p?? ep?t??pe?
µetaß???? st?? ???p???s? ?a? st?? afa??es?
t?p??et??ta? ?a? ta d?? µ??? se d?af??et????
?e?a???e? ???se??.
32
Composite (S???et?) 1/5
  • ?at?????a Structural
  • S??p??
  • S????te? a?t??e?µe?a se de?d??e?de?? (s???ete?)
    d?µ?? ??a t?? a?apa??stas? ?e?a?????
    tµ?µat??-????. ?? p??t?p? s?ed?as?? "S???et?"
    ep?t??pe? sta p?????µµata pe??te? ?a
    d?a?e??????ta? µe e??a?? t??p? t?s? ta a?e???t?ta
    a?t??e?µe?a ?s? ?a? s????se?? a?t??e?µ????.
  • S?????µa -

33
Composite (S???et?) 2/5
  • ??a efa?µ??? µp??e? ?a pe????e? ? ?a
    pe???aµß??e? s???eta
  • a?t??e?µe?a (p.?. G?af???) ? µeµ???µ??a
    a?t??e?µe?a
  • (p.?. G?aµµ?).
  • ?? ???aµe ?a p??s??s??µe st? s?st?µa µ?a ??a
    s???et? ???s?
  • (p.?. ?????a), t?te ? ??d??a? t??
    p?????µµat?? pe??t?,
  • ?a p??pe? ?a t??p?p????e? ??a ?a e??a?
    d??at?? ? ?e???sµ?? t??
  • ???? a?t??e?µ???? t?p?? ?????a?.
  • ?? p??t?p? S???et? d??e? t? ??s?. ??µ???????µe
    µ?a ???s? p??
  • epe?te??e? t?? ßas??? ???s? a?t??e?µ????
    ?a? ?e????eta? µe t??
  • ?d?? t??p? t?s? ta µeµ???µ??a a?t??e?µe?a,
    ?s? ?a? ta s???eta.

34
Composite (S???et?) 3/5

????t??
  • ??? ??????ta? ?? µ???d?? Add(), Remove(),
    getChild()
  • St?? Component ??a d?af??e?a
  • (?d?a ?e?t?????a ??a ??a ta
  • a?t??e?µe?a)
  • St?? Composite ??a asf??e?a (???e
  • ???s? ap? ep?µ????? a?t??. ?a
  • p???a??se? ????? ?at? t?? µeta???tt?s?.

35
Composite (S???et?) 4/5
Component ??a ßas??? ???s? a?t??. ? d?epaf?
(p.?. G?af???) Composite ??a s???et? ???s? (p.?.
S?ed?as?) Leaf ??a ap?? a?t??e?µe??. ?
composite s?????? e??a? µ?a s???et? d?µ? t?p??
Collection.
36
Composite (S???et?) 5/5
?a??de??µa ?e??? ?st?at?????
37
Visitor (?p?s??pt??) 1/6
  • ?at?????a Behavioral
  • S??p??
  • ???a? t? p??t?p? p?? ep?t??pe? t?? e?t??es?
    ?e????st??
  • ?e?t??????? se a?t??e?µe?a µ?a? d?µ??
    a?t??e?µ????.
  • ? ?p?s??pt?? ep?t??pe? t?? ???sµ? µ?a? ??a?
    ?e?t?????a? ?????
  • ?a a??????? ?? ???se?? t?? a?t??e?µ???? sta ?p??a
    ?a efa?µ?ste?
  • a?t? ? ??a ?e?t?????a.
  • S?????µa -

38
Visitor (?p?s??pt??) 2/6
  • ??te ???s?µ?p??e?ta? ? Visitor
  • ?ta? apa?te?ta? ? p??s???? µ?a? ??a? µe??d?? se
    µ?a ?p?????sa
  • ?e?a???a ???se?? a??? de? p??pe? ?a
    t??p?p??????? ?? ???se??
  • t?? ?e?a???a?.
  • ? ??a ?e?t???????t?ta p??st??eta? e????a se µ?a
    ?p????s? (Visitor)
  • p?? ???????µe? ap? µ?a af???µ??? ???s?.
  • G?a ?a ???p????e? ???s?µ?p??e? t? d?p??
    ap?st??? µ???µat??
  • (dual dispatch)
  • St? "d?p?? ap?st???" ? ?e?t?????a p??
    e?te?e?ta? e?a?t?ta?
  • ap? t? ???µa t?? a?t?s?? ?a?
  • t?? t?p? d?? ap?de?t?? (st? s???e???µ??? p??t?p?
    ap? t??
  • t?p? t?? Visitor ?a? t?? t?p? t?? st???e???
    p?? ep?s??pteta?).

39
Visitor (?p?s??pt??) 3/6
  • Element ????e? µ?a µ???d? accept()
  • µe pa??µet?? t? a?t??. visitor.
  • ConcreteElement ???p??e? µ?a µ???d? accept() µe
    pa??µet?? t? a?t. visitor.
  • Visitor ????e? µ?a ?e?t?????a visit()
  • ??a ???e a?t??. ConcreteElement. ??
  • ???µa ?a? ? ?p???af? t?? ?e?t?????a?
  • d??????? t?? ???s? p?? st???e? t?? p??s???s?.
    ?ts? ? visitor e?e??e?
  • st? a?t?st???? a?t??e?µe??.
  • ConcreteVisitor ???p??e? ???e ?e?t?????a p??
    ????e? ? visitor ??a
  • ???e a?t??e?µe??.
  • ObjectStructure (program)
  • µp??e? ?a e??a? d?as??des? p??
  • ep?t??pe? t?? visitor ?a ?a??se? ta
  • a?t??e?µe?a
  • - µp??e? ?a e??a? µ?a ??sta ? ??a set

40
Visitor (?p?s??pt??) 4/6
??? ???eta? ? ep?s?e?? - ??s? public µe??d??
(p??sp??as? ap? µ?a ???s? se ????). - St??
visitor ep?s?e?? se ???e ???s? s?µa??e? ???s?
µ?a? µe??d?? t?? accept() p?? ?a ??e? sa?
pa??µet?? t? a?t??. t?? visitor ?a? sa? ep?st??f?
t?? ???s? t?? µe??d?? visit() µe pa??µet?? t??
ea?t? t?? (this). ???ad? ??a ???e a?t??e?µe?? ?a
p??pe? ?a ?a?e?ta? ? µ???d?? public void
accept(Visitor v) v.visit(this) //call
visitor method ??p?? ap?st??? µ???µat??
(dual dispatch) ? µ???d?? accept() µ?s? t??
"d?p??? ap?st????" ?a??d??e? t? ??? t?? e??????
st?? ?at?????? ???s? Visitor ?a? st? s????e?a
st?? e?t??es? t?? ?e?t???????t?ta? st?? ep???µ?t?
a????? ???s?.
41
Visitor (?p?s??pt??) 5/6
?a??de??µa St?? pa?a??t? ???se?? p?? ?a
?e?????µasta? µ?a s?????? ap? p??s?pa (p.?. µ?a
e?t?p?s? t?? ???µ?t??)
42
Visitor (?p?s??pt??) 6/6
?p??tas? s?µpe??f???? (ed? e?t?p?s? t??
d?e????se?? t?? p??s?p??)
43
Observer (?a?at???t??) 1/4
?at?????a Behavioral S??p?? ????e? µ?a s??s?
e???t?s?? ??a-p???-p???? µeta?? a?t??e?µ???? ?ts?
?ste ?ta? µetaß???eta? ? ?at?stas? e???
a?t??e?µ????, ??a ta e?a?t?µe?a a?t??e?µe?a ?a
e??µe?????ta? ?a? ?a t??p?p?????ta? a?t?µata.
S?????µa Dependents, Publish-Subscribe,
Model-View
44
Observer (?a?at???t??) 2/4
  • ? s??e??as?a a????ep?d???t?? a?t??e?µ????
    ep?f??e? ?????
  • s??e???. ? ?a?at???t?? µe???e? t? s??e???
    µeta?? t??
  • a?t??e?µ????.
  • ?a s??e??a??µe?a µ??? e??a? d?? t? ?p??e?µe??
    ?a? ?
  • pa?at???t?? (s??s? ??a?-p???-p????).
  • ?? ?p??e?µe?? d?at??e? ta ded?µ??a, e?? ??
    ?e?t?????e? p??
  • af????? t?? pa?at???s? t?? ded?µ????
    ?ata??µeta? se
  • a?t??e?µe?a - pa?at???t??.
  • ?ta? ??a a?t??e?µe?? a????e? ?at?stas?, t?te
    a?a??????e? p???
  • ????? t??? ?ata????µ????? pa?at???t?? t??
    t?????sa a??a??.

45
Observer (?a?at???t??) 3/4
46
Observer (?a?at???t??) 4/4
Write a Comment
User Comments (0)
About PowerShow.com