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

CSE360 Flipped Lecture 06

CSE360 Flipped Lecture 06

Introduction to Software Engineering
Objects and Patterns
(202010)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

June 06, 2020
Tweet

Transcript

  1. CSE 360 Introduction to Software Engineering Lecture 06: Objects and

    Patterns Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. Key Ideas CSE360

  3. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 3 Key

    Concepts Encapsulation Abstraction Hierarchical Relationships Polymorphism Concurrency Persistency
  4. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 4 Abstraction

    • Reducing by focusing on the essential observable behavior • What will be outside? OOAD, Booch Textbook
  5. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 5 Encapsulation

    • Hiding the details of the implementation • What is inside? OOAD, Booch Textbook
  6. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 6 Hierarchical

    Relationships • Creating a hierarchy of abstractions • Who (is a…, uses a…, has a…) ? OOAD, Booch Textbook
  7. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 7 Hierarchical

    Relationships Association Aggregation Composition Generalization Realization
  8. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 8 8

    Hierarchical Relationships
  9. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 9 Polymorphism

    • The condition of denoting different forms. • A single name may denote objects of many different classes that are related by some common superclass. • When to use it?
  10. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 10 High

    cohesion Low coupling Important
  11. Next Step

  12. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 12 The

    LEGO Paradigm
  13. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 13 Patterns

    are these Blocks • Design patterns are solutions to software design problems you find again and again in real-world application development. • Patterns are about reusable designs and interactions between objects. • The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns (Gamma, Helm, Johnson, and Vlissides).
  14. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 14 GoF

    Patterns
  15. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 15 Blueprint

  16. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 16 GoF

    Patterns
  17. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 17 Observer

  18. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 18 Observer

  19. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 19 Observer

    Java Listeners
  20. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 20 GoF

    Patterns
  21. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 21 Decorator

  22. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 22 Examples

  23. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 23 Decorator

  24. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 24 Examples

    Java UI Objects
  25. To be continued… Review the code in the slides at

    the end with examples of Observer and Decorator
  26. Observer Pattern Example with Java API

  27. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 27 Scenario

    Observer + update() Observable + addObserver() + notifyObservers() + setChanged() Tutor Student Classroom
  28. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 28 Student

    import java.util.Observable; import java.util.Observer; public class Student implements Observer { public String answerQuestion (String question) { return "I am thinking about \'" + question +"\'"; } @Override public void update(Observable o, Object arg) { String x = ((Tutor)o).getQuestion(); String y = this.answerQuestion(x); System.out.println(y); } }
  29. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 29 Tutor

    import java.util.Observable; public class Tutor extends Observable { private String [] questions = { "2 + 2", "public or private", "functional or not fuctional", "white or black" }; private String theQuestion; public void askQuestion() { theQuestion = questions[((int)(Math.random()*10))%4]; setChanged(); notifyObservers(); } public String getQuestion() { return theQuestion; } }
  30. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 30 Classroom

    public class Classroom { public static void main(String[] args) { Student student = new Student(); Tutor tutor = new Tutor(); tutor.addObserver(student); for (int i=0; i<5;i++) tutor.askQuestion(); } }
  31. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 31 Output

  32. Decorator Pattern Example with Java

  33. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 33 Decorator

  34. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 34 Main

  35. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 35 Companion

    public interface Companion { public void doSomething(); }
  36. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 36 BasicCompanion

    public class BasicCompanion implements Companion { @Override public void doSomething() { System.out.print("Hello Student, "); } }
  37. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 37 CompanionDecorator

    public class CompanionDecorator implements Companion { protected Companion c; public void add(Companion c){ this.c = c; } @Override public void doSomething() { this.c.doSomething(); } }
  38. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 38 HelperCompanion

    public class HelperCompanion extends CompanionDecorator { @Override public void doSomething(){ super.doSomething(); System.out.print(" I am here to help you. "); } }
  39. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 39 AffectiveCompanion

    public class AffectiveCompanion extends CompanionDecorator { @Override public void doSomething(){ super.doSomething(); System.out.print(" I am here to cheer you."); } }
  40. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 40 Homework

    Complete This Week’s Hybrid Activities
  41. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 41 References

    Chapter 5
  42. CSE360 – Introduction to Software Engineering Javier Gonzalez-Sanchez javiergs@asu.edu Fall

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