CSC 313 – Advanced Programming Topics. Open-Closed Principle Classes should be open for extension, but closed to modification  So, what does this mean?

Slides:



Advertisements
Similar presentations
Lesson Overview 1.1 What Is Science?.
Advertisements

Let’s Learn Microsoft PowerPoint 1.Click on start 2.All Programs 3.Microsoft Office 4.Microsoft Office Power Point 5.Click on program to open.
Dynamic Typing COS 441 Princeton University Fall 2004.
Chapter 3: The Decorator Pattern
Scientific Method.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Behavioral Models – Direct Instruction. 1. Development is a direct result of outside experiences 1. Development is a direct result of outside experiences.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 More design patterns.
1 Software Maintenance and Evolution CSSE 575: Session 6, Part 1 The “SEAM” Model Steve Chenoweth Office Phone: (812) Cell: (937)
How to Make a Web Page: A Crash Course in HTML programming.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Scientific Method Film Canister Lab.
PRIMARY/SECONDARY SOURCE HISTORY LABS SOCIAL STUDIES CRITICAL THINKING LABS.
Misunderstood Minds 1.
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?
ASTPHND ASTPHND Innovative Applications and Training Strategies.
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.
CSC 395 – Software Engineering Lecture 12: Reusability –or– Programming was Bjarne Again.
Albert Einstein Two things are infinite: the universe & human stupidity; and I'm not sure about the universe.
CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Dynamic Games & The Extensive Form
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,
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.
McGraw-Hill Career Education © 2008 by the McGraw-Hill Companies, Inc. All rights reserved. Office Word 2007 Lab 2 Revising and Refining a Document.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
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.
Frameworks & Patterns Use of Organized Classes. Frameworks vs Toolkits Framework Framework  Start with classes and interfaces that define a rudimentary.
Lesson Overview Lesson Overview What Is Science? Lesson Overview 1.1 What Is Science?
CSC 313 – Advanced Programming Topics. Observer Pattern in Java  Java ♥ Observer Pattern & uses everywhere  Find pattern in JButton & ActionListener.
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.
CSC 313 – Advanced Programming Topics. Strategy Pattern Usage public class RubberDuck extends Duck { FlightBehavior flyBehavior; QuackBehavior quackBehavior;
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11 Modified by Donghui Zhang Jan 30, 2006.
Chapter 8: Aspect Oriented Programming Omar Meqdadi SE 3860 Lecture 8 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Lesson Overview Lesson Overview What Is Science? Lesson Overview 1.1 What Is Science?
Review of Parnas’ Criteria for Decomposing Systems into Modules Zheng Wang, Yuan Zhang Michigan State University 04/19/2002.
CS 210 Review October 3, 2006.
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.
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.
The Observer Design Pattern Author :Erich Gamma, et al. Source :Elements of Reusable Object-Oriented Software Speaker : Chiao-Ping Chang Advisor : Ku-Yaw.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Week 4 Object-Oriented Programming (1): Inheritance
Factory Method, Abstract Factory, and More
Object Oriented Practices
Objects First with Java
lecture 08, OO Design Principle
Code Smells 1.
Object Oriented Design Patterns - Structural Patterns
OO Design Patterns - Decorator
Decorator Pattern Richard Gesick.
11. MVC SE2811 Software Component Design
11. MVC SE2811 Software Component Design
Presentation transcript:

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  Want to update other’s code  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

More Reality Check …But closed to modification your  Nobody better mess with your code  YOUR code being beauty incarnate usually  Only add errors & will soil your perfection  Never let anyone:  Make changes which violate basic assumptions  Alter tasks it performs perfectly already  Anything that might introduce bugs

Strategy Pattern & OCP  Pattern stays true to open-closed principle  Using pattern, context open for extension  New functionality created by changing strategy  If more data is needed, subclasses can add fields  Context closed to modification despite all this  Actions limited by data provided to strategies  Strategies focused on task & cannot do other acts

Observer Pattern & OCP  Observer pattern devotee of principle, too  Using this pattern, subject open for extension  Responding to events open to each Observer  In pull model, extend Subject to make more info  Cannot modify Subject using this pattern  Limits of pattern means Observers 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

Inspiration For Pattern

Making a Cultured Pearl  Pearl made when piece of shell enters oyster  Irritant required to start making of pearl  To avoid irritation, shell grown around it  Layer after layer of material added by the oyster  As it grows, each layer adds new affect  Color, shine, shape modified by every layer added but always a pearl  So each layer adds something, but always a pearl

Problem At Hand  Have single key main concept  Coffee  Paycheck  Pizza  Characters  But many ways to adjust and extend concept  Cream, sugar, soy, mocha, caffeine, whip, chains  Federal & State income tax, FICA, health insurance  Bacon, pineapple, ham, anchovies, mushrooms  Bold, italic, underline, color, SMALL CAPS, error

Add Fields for properties  Add field for each possible property  Is double whip, decaf, soy water possible?  Multiple states need taxes; how to handle this?  Using fields is both hard & inefficient  Must modify class for each new property we need  Creates huge number of rarely used fields

Add Fields for properties  Add field for each possible property  Is double whip, decaf, soy water possible?  Multiple states need taxes; how to handle this?  Using fields is both hard & inefficient  Must modify class for each new property we need  Creates huge number of rarely used fields  Class open to everyone to play with & change  This very clear violation of open close principle

Create Subclasses  Define subclass for each possible situation  Need both MochaWhipCoffee & WhipMochaCoffee?  Every pizza topping combination must be written  Good news: this follows open-close principle  But code duplicated in many places  Who’ll modify classes to update New York tax rate?  Maintaining this code will be pain for someone

Decorator Pattern Intent

Decorator Pattern Usage

For Next Lecture  Lab #2 due before next lab  Asks you to implement the Strategy Pattern  Read rubric  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?