jgs CSC 307 Introduction to Software Engineering Lecture 10: Design Patterns Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 3 public class A extends B { C c1, c2; public A() { c1 = new C(); } public void method() { D d = new D(); d.working(); } } Public class X { public void m() { B var = new A(); double x = Math.sqrt(5); } } public class B implements E { public B() { C c1 = new C(); } public void method() { B b = new B(); b.sleep(); } } public class Y { A [] a = new A[5]; } Review
jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 9 § 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
jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 23 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
jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 31 Java API Java 9 deprecated Observer and Observable implementation in java.util package. It deprecated its own implementation of the concept, not the concept itself Why? serialization and thread safety problems. Solution: PropertyChangeListener from java.beans package.
jgs Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 62 Office Hours Tuesday and Thursday 3 - 5 pm But an appointment required Sent me an email – [email protected]
jgs CSC 307 Introduction to Software Engineering Lab 10: Design Patterns Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
jgs CSC 307 Introduction to Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Summer 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.