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)

Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

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

    Patterns Dr. Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 3 Key

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

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

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

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

    Relationships Association Aggregation Composition Generalization Realization
  7. 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?
  8. 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).
  9. To be continued… Review the code in the slides at

    the end with examples of Observer and Decorator
  10. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 27 Scenario

    Observer + update() Observable + addObserver() + notifyObservers() + setChanged() Tutor Student Classroom
  11. 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); } }
  12. 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; } }
  13. 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(); } }
  14. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 35 Companion

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

    public class BasicCompanion implements Companion { @Override public void doSomething() { System.out.print("Hello Student, "); } }
  16. 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(); } }
  17. 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. "); } }
  18. 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."); } }
  19. Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 40 Homework

    Complete This Week’s Hybrid Activities
  20. CSE360 – Introduction to Software Engineering Javier Gonzalez-Sanchez [email protected] 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.