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
Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 4 Abstraction • Reducing by focusing on the essential observable behavior • What will be outside? OOAD, Booch Textbook
Javier Gonzalez-Sanchez | CSE360 | Fall 2020 | 6 Hierarchical Relationships • Creating a hierarchy of abstractions • Who (is a…, uses a…, has a…) ? OOAD, Booch Textbook
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?
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).
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); } }
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(); } }
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. "); } }
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."); } }
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.