Patterns. Design comes from Modeling (requirements, analysis, problem) Mending (patch, refactoring) Memory (patterns, recall)

Slides:



Advertisements
Similar presentations
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Advertisements

Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Smalltalk Coding Patterns mostly from Smalltalk Best Practice Patterns Kent Beck Prentice-Hall, 1997.
Design Patterns Yes, they are important Robert Cotton April 23, 2009.
CS427 Topics in Software Engineering
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Design Patterns CS is not simply about programming
Ralph Johnson - University of Illinois1 Patterns: What They Are, and How to Write Them Ralph Johnson University of Illinois at Urbana-Champaign
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
OOHDM Hypermedia Research Work Designing Web-based applications with Object Oriented Hypermedia Design Method OOHDM.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
ASP.NET Programming with C# and SQL Server First Edition
CS427 - lecture 11 CS427 Topics in Software Engineering Ralph Johnson:
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Chapter 1: The Database Environment
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Design Patterns Trends and Case Study John Hurst June 2005.
S.Ducasse Stéphane Ducasse 1 Smalltalk Coding Idioms.
SE-1010 Dr. Mark L. Hornick 1 Introduction to Object-Oriented Programming (OOP) Part 1.
CSSE 374: Introduction to Gang of Four Design Patterns
Advanced topics in software engineering CSC532 Term Paper Design Patterns Harpreet Singh Submitted By:-
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
Aniruddha Chakrabarti
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
BTS430 Systems Analysis and Design using UML Design Patterns.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
A Reference Model for Event Patterns Christian Silberbauer
Encapsulation and Data Abstraction Testing Applications in Smalltalk.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
© Siemens AG, CT SE, Prashant Jain, October 15, 2001 C O R P O R A T E T E C H N O L O G Y OOPSLA 2001 Workshop Software & Engineering Architecture 1 A.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Structural Design Patterns
Factory Method Chris Colasuonno Also known as “Virtual Constructor”
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
Patterns Composite Pattern. Patterns All designers use patterns. Patterns in solutions come from patterns in problems. "A pattern is a solution to a problem.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
Game Programming Patterns From the book by Robert Nystrom
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
The Observer Design Pattern Author :Erich Gamma, et al. Source :Elements of Reusable Object-Oriented Software Speaker : Chiao-Ping Chang Advisor : Ku-Yaw.
1 CS590L Distributed Component Architecture Yugi Lee STB #555 (816) * This presentation is prepared based.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Principles and examples
Design Patterns: MORE Examples
MPCS – Advanced java Programming
Pertemuan 08 Design Patterns & Anti-Patterns
Design Patterns Introduction
Behavioral Design Patterns
Refactoring II 21-Sep-18.
DESIGNING YOUR SYSTEM.
Refactoring II 5-Feb-19.
Introduction to Design Patterns
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Object-Oriented PHP (1)
Introduction To Design Patterns
Presentation transcript:

Patterns

Design comes from Modeling (requirements, analysis, problem) Mending (patch, refactoring) Memory (patterns, recall)

Patterns Things that repeat. Solutions to a problem in a context. Patterns for coding/low-level design / architecture/user interface/problem domain

Coding patterns Smalltalk Best Practice Patterns Kent Beck Prentice-Hall, 1997

OOD patterns Design Patterns: Elements of Reusable Object-Oriented Software Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Addison Wesley, 1995.

Architectural Patterns Pattern-Oriented Software Architecture F. Buschmann, R. Meunier, H. Rohnert, P.Sommerlad, M. Stal Wiley,

Business Software Patterns of Enterprise Application Architecture Martin Fowler et. al. Addison-Wesley,

Domain Driven Design Eric Evans Addison-Wesley,

Security patterns Munawar Hafiz /patterns/index.htm

Replication Keep a copy of data on several computers. Every time one computer makes a change, make a change on the replicas, as well.

Peer-to-peer games GUI Model GUI Model events broker

Peer-to-peer games Event-oriented, not object-oriented Easy to convert from single-cpu to distributed Easy to debug Easy if only one person can make a move at once Must synchronize simultanious moves Hard to make secure

Fault tolerance Primary and backup Messages go to everyone, only primary responds If primary doesn’t respond, backup takes over

Croquet 3D virtual world Rendering takes place on local machine Events must be synchronized, then all copies of the world are changed Opencroquet.org

Persistence Keep everything in memory Replicate for backup Synchronize with a single lock Very fast No SQL Must fit in memory

Replication Advantages: Speed – local copy is faster to access Persistence – copy on disk Fault tolerance – backup can respond immediately Disadvantages?

Replication Disadvantages: Complexity Can be hard to detect changes If changes can occur in more than one place, must synchronize. Must communicate changes – can reduce response time

How to document patterns Motivating example Definition (problem, solution) Worked out examples

How to document Get an idea. Look for good example. Write draft. Flesh out with more examples. Get feedback. Improve. Repeat as needed.

Pattern Language Patterns that a person or a group uses Christopher Alexander “A Timeless Way of Building” “A Pattern Language” A genetic code for human acts of building

Pattern Language Describes set of patterns One pattern leads to another High-level come first, then lower-level Complete set of patterns for a particular problem domain

Patterns Help you gain experience, but not a substitute for experience Can be misused - useful for experts to direct Should describe pitfalls, costs

Where to find patterns Books Conferences (PLoP, EuroPLoP) Web sites (

My research in patterns Security patterns with Munawar Hafiz Safety patterns with Lui Sha Parallel programming patterns upcrc.illinois.edu/patterns

Summary Design is hard Design is about tradeoffs There is no perfect solution, just a solution whose defects don’t bother you. Patterns are no panacea, but fit people.

Smalltalk Coding Patterns mostly from Smalltalk Best Practice Patterns Kent Beck Prentice-Hall, 1997

The Book 1. Introduction 2. Patterns 3. Behavior(Today 4. State(Next time 5. Collections 6. Classes 7. Formatting

Coding Standards Standards improve communication let code be the design make code more habitable change

Coding Standards for Smalltalk Variables have no types Names can be any length Operations named with keywords Pretty printer

Names Names should mean something. Standard protocols Object (printOn:, =) Collection (do:, add:, at:put:, size) Standard naming conventions

Intention Revealing Selector Readability of message send is more important than readability of method. Name should specify what method does, not how.

Method Names If there is already a standard name, use it instead of following these rules. Three kinds of methods change state of receiver change state of argument return value from receiver

Change state of receiver method name is verb phrase - translateBy: - add:

Change state of argument Verb phrase ending with preposition like on or to. - displayOn: - addTo:

Return value from receiver method name is noun phrase or adjective, a description rather than a command - translatedBy: - size - topLeft

Method Names Specialized names for specialized purposes. Double-dispatching methods Accessing methods Query methods Boolean property setting Converter methods

Accessing Methods Many instance variables have accessing methods, methods for reading and writing them. Accessing methods come in pairs. name, name: width, width: x, x:

When to use Accessing Methods Two opinions: Always, including an object’s own instance variable lazy initialization, subclassing is easier Only when you need to use it. better information hiding

Query Method Methods that return a value often describe the type of the value because they are noun phrases. Query methods are not noun phrases, but are predicates. How can we make the return type clear?

Query Method Prefix every query method with "is". isNil isControlWanted isEmpty Put query methods in protocol “testing”

Boolean Property Setting Don't make accessing methods whose only argument is a boolean. Create two methods beginning with ”be". (or “make”) Add "toggle" if necessary. beVisible / beInvisible / toggleVisible beDirty / beClean

Converter Method Often you want to return the receiver in a new format. Prepend "as" to the name of the class of object returned. asSet (in Collection) asFloat (in Number) asComposedText (in Text)

Converter Constructor Method A class can get cluttered with converter methods that have no relationship with its main responsibility. Make a Constructor Method in the target class that takes the object to be converted as an argument. Date fromString: ‘09/10/01’

Constructor Method Class methods that create instances are in category "instance creation methods". Creation followed by initialization is the most flexible. - Point new x: 0; y: 0 Important to preserve invariants and avoid ill-formed objects.

Constructor Method Instance creation methods should create well- formed instances. Pass all required parameters to them. - Point x: 0 y: 0 - SortedCollection sortBlock: aBlock - Set new

Constructor Parameter Method How should a Constructor Method initialize new object? Separate setters are most flexible x: aNumber y: anotherNumber ^self new x: aNumber; y: anotherNumber Must maintain invarients.

Creation Parameter Method Provide a single method that sets all the variables. Preface its name with "set", then the names of the variables. x: aNumber y: anotherNumber ^self new setX: aNumber y: anotherNumber

Shortcut Constructor Method It is verbose to keep mentioning class names, and they are duplicated. Point x: width y: height height