Patterns Protect from Change Rule: if something is going to change, make it an object. Strategy: make algorithm an object so it can change State: make.

Slides:



Advertisements
Similar presentations
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Advertisements

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
7M701 1 Software Engineering Object-oriented Design Sommerville, Ian (2001) Software Engineering, 6 th edition: Chapter 12 )
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
Programming Language Paradigms: summary. Object-oriented programming Objects are the fundamental building blocks of a program. Interaction is structured.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Design Patterns CS is not simply about programming
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Copyright © Active Frameworks, Inc.. - All Rights Reserved - V2.0 Introduction - Page L1-1 PS95&96-MEF-L1-1 Dr. M.E. Fayad Creationa l Paradigm.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Exceptions  Standardized by ANSI (Since VW 3.0) Exception is the root of the exception hierarchy: 84 predefined exceptions. The two most important classes.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Reuse Activities Selecting Design Patterns and Components
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
More OOP Design Patterns
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Design Patterns.
Software Waterfall Life Cycle Requirements Construction Design Testing Delivery and Installation Operations and Maintenance Concept Exploration Prototype.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Computing IV Singleton Pattern Xinwen Fu.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Structural Design Patterns
ECE450S – Software Engineering II
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Creational Patterns
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Design Patterns Definition:
Proxy.
OO Methodology Elaboration Iteration 2 - Design Patterns -
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Patterns Composite Pattern. Patterns All designers use patterns. Patterns in solutions come from patterns in problems. "A pattern is a solution to a problem.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Smalltalk Meta-Programming Programming Languages HUJI 2010 Yardena Meymann.
Chapter 0: Introduction
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Common Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
Distribution and components
Design Patterns with C# (and Food!)
Presentation transcript:

Patterns Protect from Change Rule: if something is going to change, make it an object. Strategy: make algorithm an object so it can change State: make state-dependent behavior an object so it can change Iterator: make the way you iterate over an aggregate an object so it can change Facade: make a subsystem an object so it can change Mediator: make the way objects interact an object so it can change Factory: make the classes of your products an object so it can change

Patterns lead to standard interfaces Decorator, Composite, Proxy Introduce new objects with same interfaces as old but that add a feature / represent a group / represent a remote object Adapter Facade

Smalltalk features impact patterns Iterator – blocks Proxy – doesNotUnderstand: Command – blocks, perform: Prototype – classes as objects Bridge – dynamic typing?

Patterns and refactoring Can think of any design pattern as a “big refactoring” Introduce design patterns when you know you need them, not when you think you might need them Refactoring to Patterns by Joshua Kerievsky

Command ConcreteCommandexecuteundo Commandexecuteundo Receiver Invoker Client

Refactoring to Command Client has number/string/… that it passes to receiver, which has a case statement to decode it. Make a method for each case. Client passes selector for method (symbol) and receiver has self perform: aCommand Make each method a command class. Client creates instance and receiver has aCommand execute: self

Composite Component Container Children CompositeLeaf Composite and Component have the exact same interface. interface for enumerating children interface for enumerating children Component implements Children() by returning empty set Component implements Children() by returning empty set interface for adding/removing children? interface for adding/removing children?

Refactoring to a Composite CompoundLeaf Missing abstract class Missing leaf classes Element Class2Class3Class1 * *

Façade Provide a unified interface to a set of interfaces in a subsystem. Define a higher-level interface that makes the subsystem easier to use. Facade

Design patterns and refactoring Complexity is the death of software Think of “before” and “after” Design pattern can be a smell

Design Pattern summary Larger conceptual unit than class/message Vocabulary Expert knowledge Not magic – design tradeoffs Not completely language independent Use wisely - experiment

Exceptions An example of reflection Using objects to implement a language

Error-handling How do you signal an error? 1) Special return value 2) Evaluate error block (map at: key ifAbsent: [ ^map at: key put: (Set with: value)]) add: value 3) Exceptions

Exceptions Module will “raise an exception” Client will “handle an exception” In Smalltalk, exception is an object. Implementation uses contexts.

Contexts context stores temporaries, method arguments, program counter, and return address thisContext gives method its own context used by debugger, exception handling, processes, backtracking

Contexts PolylineFiguredisplayOn:CompositeFiguredisplayOn:DrawingdisplayOn:

Key Idea Program handles a particular error signal. [ object doWork ] on: Error do: [ :theException |... ] Server raises the same class of exception. Error signal

Exception Handling [ x / y ] on: ZeroDivide do: [ :theException | theException return: 0] / signals an error by ZeroDivide signal

Exception Handling The ”signal" method of Exception 1) creates an Exception, 2) looks on the stack for an on:do: message that uses the class or its subclass, and 3) evaluates the second argument of the on:do: message with the Exception as the argument.

Exceptions Exceptions can have an error string. Some implementations give them other arguments, but that is not part of the standard. Exception signal signal: aMessageString

Exception Protocol resume:- return from message that signaled exception retryUsing: - abort exception handler and reevaluate its exception block return:- return from block protected by active exception handler

Multiple Handlers Exception travels down stack of contexts, looking for a handler to the exception. It evaluates the handle block of the first match.... E raise on: E do:... on: E: do:

Exception Protocol reject will cause an Exception to look for the next handler. return will throw away all contexts above the handler.

Exception Hierarchy Handler for one exception will catch all subclasses, as well. Exception Error ArithmeticError MessageNotUnderstood KeyNotFoundError

Unwind Protection Problem: program can get blown away by an exception while it is in the middle of making delicate changes. This is a problem with returns in general, even without exceptions.

Unwind Protection Solution: [self dangerousCode] ifCurtailed: [self cleanUp] The cleanup block is used if the execution stack is cut back for any reason.

Unwind Protection ensure: evaluates the cleanup block after the receiver is evaluated. Semaphore critical: aBlock self wait. aBlock ensure: [self signal]

An example processFile: aFile "Read a catalog card from the first comment. Trap and report all errors." aFile isReadable ifFalse: [^self]. [self processWithErrorsFile: aFile] on: Error do: [:ex |... ]

The Handle Block [:ex | Transcript show: ex errorString. Transcript show: ' for ', aFile asString. Transcript cr. Dialog confirm: ex errorString. ex return ]

processWithErrorsFile: aFile "Read a catalog card from the first comment." | aStream string document | aStream := aFile readStream. [...] ensure: [aStream close]

If we encounter an error [Transcript show: 'bad file ', aFile asString. ^Transcript cr]. Also, system generates errors for files that are not readable.

Halt halt "This is the typical message to use for inserting breakpoints during debugging. It behaves like halt:, but does not call on halt: in order to avoid putting this message on the stack. Halt is especially useful when the breakpoint message is an arbitrary one." Halt signal

Exception handling important in developing reusable libraries. Squeaks reflective use of contexts makes it possible to implement exception handling as a class library.