Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE564 Lecture 18

CSE564 Lecture 18

Software Design
Additional Patterns II
(202103)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 18, 2020
Tweet

Transcript

  1. jgs CSE 564 Software Design Lecture 18: Patterns and Architectures

    Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs 564 00010010 Announcement § Quiz 05 is due tonight.

    It opens at the end of the lecture
  3. jgs Bridge Decouple an abstraction from its implementation so that

    the two can vary independently.
  4. jgs 564 00010010 Bridge

  5. jgs 564 00010010 Abstraction ab = new RefinedAbstraction(); // Set

    implementation and call ab.setImplementor (new ConcreteImplementorA() ); ab.Operation(); // Change implemention and call ab.setImplementor (new ConcreteImplementorB() ); ab.Operation();
  6. jgs Strategy Define a family of algorithms, encapsulate each one,

    and make them interchangeable
  7. jgs 564 00010010 Strategy

  8. jgs 564 00010010 Strategy Context context; // Three contexts following

    different strategies context = new Context(new ConcreteStrategyA()); context.ContextInterface(); context = new Context(new ConcreteStrategyB()); context.ContextInterface(); context = new Context(new ConcreteStrategyC()); context.ContextInterface();
  9. jgs 564 00010010 Strategy vs Bridge

  10. jgs 564 00010010 Strategy vs Bridge Bridge Pattern makes a

    distinction between an abstraction and an implementation in such a way that the two can vary independently Car - Engine changing the behavior of an object at run time. Game: Weapons
  11. jgs Chain of Responsibility Avoid coupling the sender of a

    request to its receiver by giving more than one object a chance to handle the request.
  12. jgs 564 00010010 Chain of Responsibility

  13. jgs 564 00010010 Chain of Responsibility // Setup Chain of

    Responsibility Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int i=0; i<requests.lenght; i++) { h1.HandleRequest(request[i]); }
  14. jgs 564 00010010 Handler abstract class Handler { protected Handler

    successor; public void setSuccessor(Handler successor) { this.successor = successor; } public abstract void HandleRequest(int request); }
  15. jgs 564 00010010 ConcreteHandler class ConcreteHandler1 extends Handler { public

    override void HandleRequest(int request) { if (request >= 0 && request < 10) { // code here… } else if (successor != null) { successor.HandleRequest(request); } } } class ConcreteHandler2 extends Handler { public override void HandleRequest(int request) { if (request >= 10 && request < 20) { // code here } else if (successor != null) { successor.HandleRequest(request); } } }
  16. jgs 564 00010010 Chain of Responsibility vs Composite vs Decorator

  17. jgs CSE 564 Computer Systems Fundamentals Javier Gonzalez-Sanchez javiergs@asu.edu Fall

    2020 Disclaimer. These slides can only be used as study material for the class CSE564 at ASU. They cannot be distributed or used for another purpose.