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

CSC305 Lecture 10

CSC305 Lecture 10

Individual Software Design and Development
Patterns
(202410)

Javier Gonzalez-Sanchez

October 13, 2024
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227

    CSC 305 Individual Software Design and Development Lecture 10. Standard Solutions I
  2. Clean Code Re a d a bility • DRY •

    KIS • SRP • Comments • Error H a ndling with a Logger 3 Metrics • LOC (eLOC, lLOC) • CC • A • I • D
  3. De f inition • Design patterns a re solutions to

    softw a re design problems you f ind a g a in a nd a g a in in re a l-world a pplic a tion development. • P a tterns a re a bout reusable designs a nd inter a ctions between objects. • The 23 G a ng of Four (GoF) patterns a re gener a lly considered the found a tion for a ll other p a tterns (G a mm a , Helm, Johnson, a nd Vlissides). 6
  4. Observable import java.util.LinkedList; public abstract class Observable { 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); } } } 11
  5. Student as Observer 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); } } 12
  6. Teacher as Observable class Teacher extends Observable { private String

    question; public String getQuestion() { return question; } public void createQuestion () { question = // AI to create a question here notifying(); } } 13
  7. Main 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(); } } 14
  8. Lab

  9. CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D.

    [email protected] Summer 2024 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.