Albert Einstein Two things are infinite: the universe & human stupidity; and I'm not sure about the universe.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Dynamic Typing COS 441 Princeton University Fall 2004.
Chapter 3: The Decorator Pattern
SE-2811 Dr. Mark L. Hornick 1. The Decorator Pattern SE-2811 Dr. Mark L. Hornick 2.
Computer Science 313 – Advanced Programming Topics.
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
1 Software Maintenance and Evolution CSSE 575: Session 6, Part 1 The “SEAM” Model Steve Chenoweth Office Phone: (812) Cell: (937)
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Design Patterns.
CSC 395 – Software Engineering Lecture 34: Post-delivery Maintenance -or- What’s Worse than Being a Code Monkey?
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
CSC 313 – Advanced Programming Topics. Lindsay Lohan Economy  Studies investigated economy of celebrities  Direct earnings from movies, music, TV, ads.
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.
Computer Science 313 – Advanced Programming Topics.
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.
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.
Inheritance Extending Class Functionality. Polymorphism Review Earlier in the course, we examined the topic of polymorphism. Many times in coding, we.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Pattern Hatching - John Vlissides Pages 85 – 101 Todd Anderson
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Decorator Pattern So many options!. Starbuzz Coffee  Want to offer a variety of combinations of coffee and condiments  Cost of a cup depends on the.
CSC 313 – Advanced Programming Topics. Open-Closed Principle Classes should be open for extension, but closed to modification  So, what does this mean?
Computer Science 313 – Advanced Programming Topics.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
CSC 313 – Advanced Programming Topics. Decorator Pattern Intent.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Adv. Use cases Actor generalization – general and special actors Use case generalization – general and special use cases Include and extend relationships.
CSC 313 – Advanced Programming Topics. Observer Pattern in Java  Java ♥ Observer Pattern & uses everywhere  Find pattern in JButton & ActionListener.
CSC 313 – Advanced Programming Topics. What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete.
CSC 313 – Advanced Programming Topics. Strategy Pattern Usage public class RubberDuck extends Duck { FlightBehavior flyBehavior; QuackBehavior quackBehavior;
Chapter 8: Aspect Oriented Programming Omar Meqdadi SE 3860 Lecture 8 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CS 210 Review October 3, 2006.
CS 325: Software Engineering March 19, 2015 Applying Patterns (Part B) Code Smells The Decorator Pattern The Observer Pattern The Template Method Pattern.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
The Last Lecture CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
More Patterns CS 124. More Basic Patterns Patterns you’ve already seen (without knowing it) Observer / Listener Wrapper Composite Decorator / Filter Patterns.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Fred Brooks Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the.
F-1 © 2007 T. Horton CS 4240 Principles of SW Design More design principles LSP, OCP, DIP, … And another pattern Decorator.
Eagleson’s Law: Any code of your own that you haven't looked at for 6+ months might as well have been written by someone else.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
Bjarne Stroustrup I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my.
Computer Science 313 – Advanced Programming Topics.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
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.
The Decorator Pattern Decorators in Java I/O classes SE-2811 Dr. Mark L. Hornick 1.
Builder Introduction. Intent Separate the construction of a complex object from its representation so that the same construction process can create different.
Common Design Patterns
Week 4 Object-Oriented Programming (1): Inheritance
Factory Method, Abstract Factory, and More
MSIS 670 Object-Oriented Software Engineering
lecture 08, OO Design Principle
Object Oriented Design Patterns - Structural Patterns
OO Design Patterns - Decorator
Decorator Pattern Richard Gesick.
If you only want to put data in certain fields, list them in the Insert and then insert values for just those fields.
Software Design Lecture : 12.
7. Decorator SE2811 Software Component Design
Design Patterns Lecture part 1.
Presentation transcript:

Albert Einstein Two things are infinite: the universe & human stupidity; and I'm not sure about the universe.

CSC 313 – Advanced Programming Topics

Open-Closed Principle Classes should be open for extension, but closed to modification  So, what does this mean?

Reality Check Classes should be open for extension…  Other’s code can be updated  Other is important emphasis  Everyone is other to someone  Easily create subclasses to:  Add functionality  Include additional fields  Specialize behavior via overriding

More Reality Check …But closed to modification  Nobody better mess with your code  YOUR code generally being beauty incarnate  Only add errors & soil your perfection  Never let anyone:  Add functionality violating its basic assumptions  Alter the tasks it performs  Anything that might introduce bugs

Strategy Pattern & OCP  Pattern stays true to open-closed principle  Context remains open for extension  Strategies add new functionality  Subclasses provide additional fields  But also remains closed to modification  Strategies must use data provided to them  Can only perform actions for which defined

Observer Pattern & OCP  Observer pattern also principle devotee  Subject remains open for extension  Observers provide ways of handling events  In pull model, extend Subject to provide more information to Observers  But also remains closed to modification  Observers cannot ACT, but only RE-ACT  Subject chooses events to expose to Observers

Warning Remainder of lecture unsafe for: Beginning programmers Unwilling to consider new viewpoints Stubbornly dogmatic Stupid Liberal arts majors

Problem At Hand

Add fields for properties  Add field for each possible property  Does double whip, decaf, soy water make sense?  How to handle taxes for multiple states?  Adding fields is also inefficient  Must modify class for each new property  Creates huge number of rarely used fields  Class remains open for anyone to play with  Violates the open close principle

Create subclasses  Define subclass for each possible situation  Need both MochaWhipCoffee & WhipMochaCoffee?  Volunteers writing all pizza topping combinations?  Does not violate open-close principle  But code duplicated in many places  Who’ll modify classes to update New York tax rate?  Maintaining this code will be major pain in the ass

Decorator Pattern Intent

Decorator Pattern Usage  Flexibly add adjectives to main class’s noun  Decorations provide additional description  Each decoration not always required  Wrappings can be stacked in any order  Add adverbs to enhance main class’s actions  Improve result using additional information  Include additional tasks that must be performed  Invisibly augment main class instances

For Next Lecture  Lab #3 available on web/Angel  Asks you to implement the Observer Pattern  Due before lab on Tuesday  Read pages 95 – 105 in the book  How do we implement the DESIGN PATTERN?  Can anyone actually use this?  What is the main point of this pattern?