CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

Recursion vs. Iteration The original Lisp language was truly a functional language: –Everything was expressed as functions –No local variables –No iteration.
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Computer Science 313 – Advanced Programming Topics.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Computer Science 313 – Advanced Programming Topics.
Delegates & Events Observer and Strategy Patterns Game Design Experience Professor Jim Whitehead January 30, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
MVC and MVP. References enter.html enter.html
CISC6795: Spring Object-Oriented Programming: Polymorphism.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
CSC 313 – Advanced Programming Topics. Lindsay Lohan Economy  Studies investigated economy of celebrities  Direct earnings from movies, music, TV, ads.
CSC 213 – Large Scale Programming Lecture 3: Object-Oriented Analysis.
CSC 313 – Advanced Programming Topics. Observer Pattern Intent  Efficiently perform 1-to-many communication  Easy to respond dynamically when event(s)
Prof. Hertz (as told by xkcd.com)‏. Computer Science 313 – Advanced Programming Topics.
Albert Einstein Two things are infinite: the universe & human stupidity; and I'm not sure about the universe.
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
CS 210 Introduction to Design Patterns September 7 th, 2006.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
Beware of bugs in the above code; I have only proved it correct, not tried it.
SE: CHAPTER 7 Writing The Program
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
CS 350 – Software Design The Strategy Pattern – Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore.
CSC 313 – Advanced Programming Topics. Open-Closed Principle Classes should be open for extension, but closed to modification  So, what does this mean?
Strategy Design Patterns CS 590L - Sushil Puradkar.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
CSC 313 – Advanced Programming Topics. Observer Pattern in Java  Java ♥ Observer Pattern & uses everywhere  Find pattern in JButton & ActionListener.
Observer Please Snarf the Code for Today’s Class..
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
CSC 313 – Advanced Programming Topics. What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete.
Chapter 18 The Observer Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Chapter 8: Aspect Oriented Programming Omar Meqdadi SE 3860 Lecture 8 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Religious Studies 313 – Advanced Programming Topics.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
INFO 620Lecture #71 Information Systems Analysis and Design Design Class Diagrams and others INFO 620 Glenn Booker.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
More Patterns CS 124. More Basic Patterns Patterns you’ve already seen (without knowing it) Observer / Listener Wrapper Composite Decorator / Filter Patterns.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Slide design: Dr. Mark L. Hornick
Strategy: A Behavioral Design Pattern
Abstract Factory Pattern
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
CS 350 – Software Design The Strategy Pattern – Chapter 9
Behavioral Design Patterns
Observer Design Pattern
Abstract Factory Pattern
Un</br>able’s MySecretSecrets
Intent (Thanks to Jim Fawcett for the slides)
Presented by Igor Ivković
structures and their relationships." - Linus Torvalds
Refactoring Types Blake Duncan.
Design pattern Lecture 9.
Strategy Design Pattern
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Informatics 122 Software Design II
structures and their relationships." - Linus Torvalds
Refactoring.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

CSC 313 – Advanced Programming Topics

Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being

 Each design pattern is a tool  Like all most tools, have reason for being  Explains when & where to use pattern  Tool used improperly is sad  Ryan Seacrest is truly depressed  Programmer’s goal is to match need to pattern  Coding is simple when used properly  More importantly, life just sucks when you don’t Design Pattern Intent

Strategy Pattern Intent  Makes family of algorithms interchangable  Avoid duplicating code across classes & projects  Allows to change algorithm dynamically  Fairly straightforward to implement  Set of behaviors (strategies) implementing interface  Context has field of the interface type  Performs action by calling method on field

Observer Pattern Intent  What is the intent of observer pattern?

Observer Pattern Intent  Efficiently perform 1-to-many communication  Easy notification of Observers when event occurs  Can also use to break mutual dependency  UML class diagram cycles split and managed  Dirty, ugly, incredibly useful hack

Registering an Observer  Efficiently perform 1-to-many communication  Subject adds & removes Observers as needed  Adding is simple  Events also simple, call Observers’ update method  Removing not so simple, but not very hard either  Requires some means of holding Observers  Array *  ArrayList or LinkedList  HashMap

Registering an Observer

Getting the Word Out  Calling Observers’ update methods is simple  Good ways of passing data is difficult  Bad to rely on simple parameters for method  Updating parameters requires changing all code  Can use strategy pattern to supply information  Yay! Keeps our classes independent of each other

Good, bad, & ugly  Efficiently perform 1-to-many communication  Strategy pattern defines functionality  But observer pattern only for communication  Observers & subject independent of each other  Subject & strategy semi-independent of other  Observer & strategies entirely inter-dependent  Observer must know Strategy’s algorithm

Push vs. Pull  So far discussed pattern’s push model  Subject pushes data onto the Observers  At all times, must keep Observer prepared  Much harder to change code & what happens  Could instead use pattern’s pull model  Subject provides an instance to the Observers  To get data, Observers call instance’s methods  Extend instance’s class to provide additional data  But, Observers using original methods still work

Problems with Pull Model  Pull model also has its problems  Adds many method calls to get access to data  Can cause problems in multi-threaded systems  Interfere with other design patterns, if also used  These problems are both easier & harder  Only with later concept from CSC330 & CSC313  But these issues cannot be easily avoided…  …and very serious on large real-world systems

Other Observer Gotchas  Observer only needs some of the events  Still performs 1-to-many communication  Subject cannot filter events for each Observer  But easier to add another Observer to filter  Subject has multiple sets of events to observe  Could choose to rely on single Observer interface  Java AWT/Swing libraries use this approach  Multiple Observer interfaces each with 1 event  Simpler, but less efficient if multiple events wanted

For Next Lecture  Read pages 70 – 74 in book  What is the Observable object in Java?  How would one use it?  Why would anyone write it that way?