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

CSC308 Lecture 13

CSC308 Lecture 13

Software Engineering I
Design Patterns
(202302)

Javier Gonzalez-Sanchez

October 19, 2022
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs CSC 308 Software Engineering 1 Lecture 13: Design Patterns

    Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
  2. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    3 Not Everything that Can be … Should be …
  3. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    5 Homework (1 of 2) Single Responsibility Principle
  4. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    7 § 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). Definition
  5. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    8 Timeline 1989 Beck OO Thinking 1993 Gamma et al. GoF Patterns
  6. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    14 class Student { public String answerQuestion (String question) { String answer; // solve the question return answer; } } Student
  7. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    15 class Teacher { private String question; public String getQuestion() { return question; } public void createQuestion () { question = // AI to create a question here } } Teacher
  8. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    17 public abstract class Observer { public abstract void update(Subject s); } Observer
  9. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    18 import java.util.LinkedList; public abstract class Subject { private LinkedList<Observer> observers = new LinkedList<Observer>(); public void addObserver(Observer observer) { observers.add(observer); } public void removeObserver(Observer observer) { observers.remove(observer); } public void notifying() { for (Observer ob : observers) { ob.update(this); } } } Observable
  10. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    19 class Student extends Observer { public String answerQuestion (String question) { String answer; // solve the question return answer; } @Override public void update(Observable s) { String q = ((Teacher)s).getQuestion(); Sting answer = answerQuestion (q); System.out.println (answer); } } Student as Observer
  11. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    20 class Teacher extends Observable { private String question; public String getQuestion() { return question; } public void createQuestion () { question = // AI to create a question here notifying(); } } Teacher as Observable
  12. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    21 public class Main { public static void main(String[]a) { Teacher teacher = new Teacher(); Student s1 = new Student(); Student s2 = new Student(); teacher.addObserver(s1); teacher.addObserver(s2); // Teaching teacher.createQuestion(); // More Teaching teacher.createQuestion(); } } Main
  13. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    22 Scenario Observer + update() Observable + addObserver() + notifyObservers() + setChanged() Teacher Student Main
  14. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    24 Office Hours Tuesday and Thursday 3 - 5 pm But an appointment required Sent me an email – [email protected]
  15. jgs

  16. jgs CSC 308 Software Engineering 1 Lab 13: Assignment 02

    Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
  17. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    28 Project – User selects Cluster and clicks Run ✅
  18. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    29 Project – User selects Cluster and clicks Run ✅
  19. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    30 Project – User selects Line and clicks Run ✅
  20. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    31 Project – User selects Line and clicks Run ✅
  21. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    32 Project – User selects Line and clicks Run ✅ ✅
  22. jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 |

    33 Project – User selects Cluster and clicks Run ✅ ✅
  23. jgs CSC 308 Software Engineering I Javier Gonzalez-Sanchez, Ph.D. [email protected]

    Winter 2023 Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly. They cannot be distributed or used for another purpose.