Week 2, Day 2: The Factory Method Pattern Other good design principles Cohesion vs. Coupling Implementing the Strategy Pattern Changing strategies (behaviors)

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

Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Open-closed principle.
Inheritance issues SE-2811 Dr. Mark L. Hornick 1.
What Is a Factory Pattern?.  Factories are classes that create or construct something.  In the case of object-oriented code languages, factories construct.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing.
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.
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.
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.
CS-2852 Data Structures Week 5, Class 1 – Testing and Stacks Return Exams & Labs  Package-level access  UML connectors for instance variables Announcement:
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.
CS-2852 Data Structures Week 5, Class 2 – Testing and Stacks Announcement: Lab Demos - 2/3 & 4 on Friday Testing  Definitions, Example  (tentative) Testing.
The Proxy Pattern SE-2811 Dr. Mark L. Hornick 1. The Proxy Pattern has many variations, but in general: The Proxy Pattern uses an proxy object as a surrogate.
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.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
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.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CS2852 Week 5, Class 2 Today Queue Applications Circular Queue Implementation Testing SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick.
Systems Requirements SE 3821 Design? Algorithms CS 2852.
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:
CS2852 Week 3, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
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.
CS2910 Week 7, Class 1 Today Capturing SMTP with Thunderbird Tomorrow Extra office hour at 11 am (right after lab) Friday Office hour cancelled SE-2811.
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.
CS-2852 Data Structures Week 5, Class 3 – Testing and Recursion Queue Implementing finite queues Binary Search Recursion Tomorrow – Quiz, Lab demos, Lab.
SE-1021 Software Engineering II
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Week 2, Day 1: The Factory Method Pattern
SE-2811 Software Component Design
SE-2811 Software Component Design
IFS410: Advanced Analysis and Design
Week 7, Class 1: The Command Pattern (cont.)
SE-2811 Software Component Design
CS 350 – Software Design Principles and Strategies – Chapter 14
14. Factory Pattern SE2811 Software Component Design
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
10. Façade Pattern SE2811 Software Component Design
14. Factory Pattern SE2811 Software Component Design
Week 6, Class 2: Observer Pattern
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
SE-1021 Software Engineering II
Slide design: Dr. Mark L. Hornick
Presentation transcript:

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

Other good design principles we visited Code to the highest level of abstraction that is possible in a given context: i. ArrayList = new ArrayList // bad ii. List = new ArrayList // good iii. Collection = new ArrayList // better

Other good design principles we visited Code to most restrictive level of access modification that is possible in a given context: i. Use public for constants and methods; never for attributes. On methods: only on those you want to support for public consumption ii. Use protected to allow derived classes in any package access to members (as well as package) iii. Use /*package*/ if cooperating classes in the same package need access to attributes or special methods iv. Use private to completely guard members from view outside the defining class

More details on package access Access Levels ModifierClassPackageSubclassWorld publicYYYY protectedYYYN /*package*/YYNN privateYNNN Adapted from Oracle’s Java tutorial ccesscontrol.html SE-2811 Dr. Mark L. Hornick 4

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 5

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 6

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 7

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! Survey: Have you heard of this before? SE-2811 Dr. Mark L. Hornick 8

The Factory Method Pattern Solution 2: Have an abstract “factory” method that instances will implement public abstract Duck { public quack{ // quack! } public abstract createDuck(Scanner in); } SE-2811 Dr. Mark L. Hornick 9

The Factory Method Pattern General Form SE-2811 Dr. Mark L. Hornick 10

The Factory Method Pattern How we will use it today SE-2811 Dr. Mark L. Hornick 11