Duke CPS 108 2. 1 Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.

Slides:



Advertisements
Similar presentations
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Advertisements

The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Plab – Tirgul 12 Design Patterns
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,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
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.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Comp2110 Software Design lecture 13Detailed Design (1)  detailed design contrasted with high level design  introducing the Observer Design Pattern 
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CSE 332: Design Patterns (Part I) Introduction to Design Patterns Design patterns were mentioned several times so far –And the Singleton Pattern was discussed.
Creational Patterns (1) CS350, SE310, Fall, 2010.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Software Design 4.1 Tell, Don't Ask l Tell objects what you want them to do, do not ask questions about state, make a decision, then tell them what to.
Design Patterns. Patterns “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution.
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
DAAD project “Joint Course on OOP using Java” On Object Oriented modeling in Java (Why & How) Ana Madevska Bogdanova Institute of informatics Faculty of.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Software Design 8.1 Compsci 108 l Object oriented design and programming of medium-sized projects in groups using modern tools and practices in meaningful.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Software Design 18.1 CPS 108 l Object oriented design and programming of medium-sized projects in groups using modern tools and practices in meaningful.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
CSC 480 Software Engineering Design With Patterns.
Software Design 14.1 CPS 108 l Object oriented design and programming of medium-sized projects in groups using modern tools and practices in meaningful.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Introduction
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS 4240: Rethinking Some OOP Ideas and Terms for OOA&D Readings: Chap. 8 in Shalloway and Trott (referred to as S&T in these slides) Wikipedia on information.
Software Design 1.1 CPS 108, Spring 2006 l Object oriented programming and design, we'll use Java and C++  Language independent concepts including design.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
Duke CPS CPS 108, Spring 1998 l Software Design and Implementation ä Object oriented programming and design ä good design helps do away with late.
Software Design 17.1 Aside: ethics of software l What is intellectual property, why is it important?  what about FSF, GPL, copy-left, open source, … 
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.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Engineered for Tomorrow Unit:8-Idioms Engineered for Tomorrow sharmila V Dept of CSE.
Design Patterns: MORE Examples
COMP2110 Software Design in lecture 14 Patterns(1) /Detailed Design
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Introduction to Design Patterns
Behavioral Design Patterns
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
object oriented Principles of software design
Beta Release Retrospective
Patterns.
CSC 480 Software Engineering
Strategy Design Pattern
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Introduction to Design Patterns
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Informatics 122 Software Design II
CSC 480 Software Engineering
Chapter 8, Design Patterns Introduction
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies and encapsulate it l Program to an interface, not an implementation ä Specify behavior by name, not by working code l Favor Composition over Inheritance ä Use "has-a" rather than "is-a" l Classes and code should be open for extension, but closed to modification ä The Open-Closed Principle

Duke CPS Tell, Don't Ask l Tell objects what you want them to do, do not ask questions about state, make a decision, then tell them what to do (Pragmatic Programmers, LLC) ä Think declaratively, not procedurally ä Don't ask for a map, then walk through the map ä Instead of iteration, apply to all Breaks when we don't want to apply to all l Rules are made to be broken ä Reduce coupling, better code

Duke CPS Law of Demeter l Don't talk to objects, don't call methods. The more you talk, the more you rely on something that will break later ä Call your own methods ä Call methods of parameter objects ä Call methods if you create the object Do NOT call methods on objects returned by calls List all = obj.getList(); all.addSpecial(key,getValue()); obj.addToList(key,getValue()); // ok here

Duke CPS Design patterns “... describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice” Christopher Alexander, quoted in GOF l Name ä good name is a handle for the pattern, builds vocabulary l Problem ä when applicable, context, criteria to be met, design goals l Solution ä design, collaborations, responsibilities, and relationships l Forces and Consequences ä trade-offs, problems, results from applying pattern: help in evaluating applicability

Duke CPS Patterns are discovered, not invented l You encounter the same “pattern” in developing solutions to programming or design problems ä develop the pattern into an appropriate form that makes it accessible to others ä fit the pattern into a language of other, related patterns l Patterns transcend programming languages, but not (always) programming paradigms ä OO folk started the patterns movement ä language idioms, programming templates, programming patterns, case studies l Patterns capture important practice in a form that makes the practice accessible

Duke CPS Pattern/Programming Interlude l Microsoft interview question (1998) l Dutch National Flag problem (1976) l Remove Zeros (AP 1987) l Quicksort partition (1961, 1986) l Run-length encoding (SIGCSE 1998)

Duke CPS One loop for linear structures l Algorithmically, a problem may seem to call for multiple loops to match intuition on how control structures are used to program a solution to the problem, but data is stored sequentially, e.g., in an array or file. Programming based on control leads to more problems than programming based on structure. Therefore, use the structure of the data to guide the programmed solution: one loop for sequential data with appropriately guarded conditionals to implement the control Consequences: one loop really means loop according to structure, do not add loops for control: what does the code look like for run-length encoding example?

Duke CPS Coding Pattern l Name: ä one loop for linear structures l Problem: ä Sequential data, e.g., in an array or a file, must be processed to perform some algorithmic task. At first it may seem that multiple (nested) loops are needed, but developing such loops correctly is often hard in practice. l Solution: ä Let the structure of the data guide the coding solution. Use one loop with guarded/if statements when processing one- dimensional, linear/sequential data l Consequences: ä Code is simpler to reason about, facilitates develop of loop invariants, possibly leads to (slightly?) less efficient code

Duke CPS Design patterns you shouldn’t miss l Iterator ä useful in many contexts, see previous examples, integral to both C++ and Java l Factory  essential for developing OO programs/classes, e.g., create iterator from a Java List? list.iterator() l Strategy ä encapsulate an algorithm as an object, supports swapping algorithms during execution l Command ä encapsulate a request as an object, supports undo, re- usable commands l Observer/Observable, Publish/Subscribe, MVC ä separate the model from the view, smart updates

Duke CPS Implications for nanoGoogle? l What might change in going from release 0.9 to 1.0 to 2.0 in nanoGoogle ä Should we worry about future changes? ä Should we make things work now? ä Can we do both? l Strategy pattern ä Algorithm varies independently from clients that use it, ä What are the algorithms in nanoGoogle?

Duke CPS Essential Features of Design Patterns l Delegation ä If many ways to do something, delegate actual details to a separate module (i.e., packages, classes, methods) ä Add an extra level of indirection to support flexibility l Substitution ä If many ways to do something, try to give it the same interface so that one can be substituted for another (i.e., member functions, method names, parameters) ä Create correct one and use it at correct time