Week 2, Day 1: The Factory Method Pattern

Slides:



Advertisements
Similar presentations
SE2811 Week 7, Class 2 The Gang of Four and more … Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder.
Advertisements

C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
Week 5, Day 3: Observer Today Reducing coupling with the Observer The Observer pattern in Java APIs Posting events to a UI worker thread SE-2811 Slide.
Week 3, Day 1: Processes & Threads Return Quiz Processes Threads Lab: Quiz Lab 3: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
Abstract Factory Design Pattern making abstract things.
SE1011 Week 2, Class 3 Today Compiling and running Another example using Scanner Compile-time and Run-time errors Review for exam SE-1011 Slide design:
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Today Quiz Multithreading Options Qt socket buffers between threads Quiz today & Tuesday in lab SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr.
Week 2, Day 2: The Factory Method Pattern Other good design principles Cohesion vs. Coupling Implementing the Strategy Pattern Changing strategies (behaviors)
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1 Class 1-2.
Week 6, Class 1 & 2: Decorators Return Exam Questions about lab due tomorrow in class? Threads Locking on null object invokeLater & the squares example.
SE-2811 Software Component Design Week 1, Day 2 (and 1-3 and 2-1) SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
Week 9, Class 3: Model-View-Controller Today Happens-Before Adapter and Façade Pattern (high-level) Tuesday: Project code due, 11pm Wednesday: Quiz Choose.
Week 3, Day 2: Threads Questions about Threads “Multithreading” in Swing Lab tomorrow: Quiz Lab 3: Threading! SE-2811 Slide design: Dr. Mark L. Hornick.
Chapter 7: The Adapter Pattern. Object Oriented Adapters Suppose that you have existing software. You have outsourced some of your work and there is a.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1.
SE1011 Week 6, Class 1 Today Return Half Exam 2 (cont.) Object Oriented Programming (cont.) Muddiest Point Next Half Exam: Week 7, Monday SE-1011 Slide.
CS2852 Week 6, Class 1 Today The run-time stack Writing and proving recursive methods SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 7, Class 1 Today Binary Search Tree Implementing add Implementing find Return Quiz 4 (second attempt) Both sections are graded SE-2811 Slide.
Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick.
Week 7, Day 3 Half-Exam 2 A New Pattern SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
SE-2811 Software Component Design Week 1, Day 2 Making teams Warm-up exercise Design pattern defined SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick.
Week 5, Day 3: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:
Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:
Today Quiz not yet graded Final report requirements posted More on Multithreading Happens-Before in Java SE-2811 Slide design: Dr. Mark L. Hornick Content:
Week 7, Class 1: The Command Pattern (cont.) Get Ready for Poll Everywhere Labs 2 & 3 returned Lab 7 due this evening at 11pm Quiz tomorrow at start of.
Slide design: Dr. Mark L. Hornick
Week 10, Day 3 Review for the quarter SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
// create some behaviors SwimBehavior csb = new CircularSwimming(); QuackBehavior sqb = new StandardQuacking(); SwimBehavior rsb = new RandomFloating();
SE-2811 Software Component Design Week 1, Day 1 Design pattern defined Code that needs a design pattern… SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick.
Week 9, Day 1 Proxy SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Week 6, Class 3: Composite Swing composites File composites Computer composites SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
Week 8, Class 3: Model-View-Controller Final Project Worth 2 labs Cleanup of Ducks Reducing coupling Finishing FactoryMethod Cleanup of Singleton SE-2811.
Week 4, Day 1: Singleton(s?) Singleton leftover Why singletons? How to make lazy initialization work multi- threaded? Observers Why observers? Class structure.
Week 5, Class 3: Decorators Lab questions? Example: Starbuzz coffee Basic Pattern More examples Design Principles Compare with alternatives SE-2811 Slide.
SE2811 Week 8 – Class 2 Re: Lab due tonight SE-2811 Slide design: Dr. Mark L. Hornick Much Content: Dr. Hornick Most Errors: Dr. Yoder 1.
Slide design: Dr. Mark L. Hornick
SE-1021 Software Engineering II
Unit II-Chapter No. : 5- design Patterns
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
SE-2811 Software Component Design
SE-2811 Software Component Design
SE-2811 Software Component Design
Week 7, Class 1: The Command Pattern (cont.)
SE-2811 Software Component Design
Structural Patterns: Adapter and Bridge
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
14. Factory Pattern SE2811 Software Component Design
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
SE-2811 Software Component Design
10. Façade Pattern SE2811 Software Component Design
14. Factory Pattern SE2811 Software Component Design
Week 6, Class 2: Observer Pattern
Designing For Testability
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Week 8, Class 3: Model-View-Controller
SE-1021 Software Engineering II
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
SE-1021 Software Engineering II
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
SE-1021 Software Engineering II
15. Proxy SE2811 Software Component Design
Slide design: Dr. Mark L. Hornick
Presentation transcript:

Week 2, Day 1: The Factory Method Pattern Other good design principles Cohesion vs. Coupling Implementing the Strategy Pattern Changing strategies (behaviors) at runtime Thursday: Quiz Lab 2: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder

Quiz Thursday Cohesion vs. Coupling What is a design pattern? For these patterns The Strategy Pattern The Factory Method Pattern These objectives: Design using this pattern at the class diagram level Implement individual methods needed for the pattern SE-2811 Dr. Mark L. Hornick

Coding Example Cleaning up example from last time Avoid back-pointers and associated interfaces Motivating Factory Methods Adding ducks SE-2811 Dr. Mark L. Hornick

The Simple Factory Programming Idiom (1) We would like to override constructors, but you can’t (at least in Java, from another class) DarkWingDuck() does not override Duck() Could you in any language? Then we could put the creation-specific code into the object that creates it. SE-2811 Dr. Mark L. Hornick

The Simple Factory Programming Idiom (2) Or (from Dr. Hornick) Client may need to incorporate intelligence such as “thread awareness” in order to create the objects on the correct thread Object creation may need to be a multi-step procedure (As on previous slide) Hard to maintain – may require a lot of different “new’s” And generally, we want to program to interfaces or abstract classes (As on previous slide) SE-2811 Dr. Mark L. Hornick

The Simple Factory Programming Idiom (3) Solution 1: Have a “Factory” class that hides away the implementation details e.g. We could create a DuckFactory class that hides the details of creating a duck But this still puts all the duck-creation details in one place! And, to solve the behavior-passing problem, we want to pass the constructor as if it were an object. SE-2811 Dr. Mark L. Hornick

The Factory Method Pattern SE-2811 6/15/2018 The Factory Method Pattern Solution 2: Have an abstract “factory” method that instances will implement public abstract Duck { public quack{ // quack! } public abstract static Duck createDuck(Scanner in); } What's wrong with this solution? ___________ SE-2811 Dr. Mark L. Hornick Dr. Yoder

The Factory Method Pattern SE-2811 6/15/2018 The Factory Method Pattern Solution 3: Have an abstract “factory” method that instances will implement public abstract class Duck { public quack{ // quack! } } public interface DuckFactory { Duck createDuck(Scanner in); SE-2811 Dr. Mark L. Hornick Dr. Yoder

The Factory Method Pattern General Form SE-2811 6/15/2018 The Factory Method Pattern General Form SE-2811 Dr. Mark L. Hornick Dr. Yoder