Interface Patterns. Adapter Provides the interface a client expects, using the services of a class with a different interface Note Avoid using object.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

Don’t reinvent the wheel. The Design Patterns Book.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Nov, 1, Design Patterns PROBLEM CONTEXT SOLUTION A design pattern documents a proven solution to a recurring problem in a specific context and its.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Patterns CS is not simply about programming
Oct, 16, Design Patterns PROBLEM CONTEXT SOLUTION A design pattern documents a proven solution to a recurring problem in a specific context and.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
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.
Design Patterns Introduction. What is a Design Pattern?  A technique to repeat designer success.  Borrowed from Civil and Electrical Engineering domains.
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
Don’t reinvent the wheel. The Design Patterns Book.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Lexi case study (Part 2) Presentation by Matt Deckard.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
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.
Structural Design Patterns
ECE450S – Software Engineering II
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.
Design Pattern Dr. Zhen Jiang West Chester University url:
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 COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since 1987 Program Director, Los Angeles Visual Foxpro Developers.
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.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
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.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Jim Fawcett CSE776 – Design Patterns Summer 2006
Abstract Factory Pattern
Chapter 10 Design Patterns.
Software Design Patterns
Don’t reinvent the wheel
Jim Fawcett CSE776 – Design Patterns Fall 2016
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Behavioral Design Patterns
Design Patterns with C# (and Food!)
object oriented Principles of software design
Abstract Factory Pattern
Design Patterns Satya Puvvada Satya Puvvada.
Design Patterns in Game Design
Presentation transcript:

Interface Patterns

Adapter Provides the interface a client expects, using the services of a class with a different interface Note Avoid using object adapter if possible because the adaptee could change and make private things the adapter uses. Errors like this are less likely to be picked up at compile time. Example JTable – You adapt an array of your custom objects to provide the TableModel interface that JTable needs Facade Provides a simplified interface making a subsystem easy to use. It lies somewhere between a toolkit and a complete application. Example JOptionPane provides a simplified way to input choices based on JPanel and JButtons Composite Lets clients treat individual objects and compositions of objects uniformly. Note composites may include more than one leaf class or composites with varied implementations of the operation method. However all must implement the component interface. Example Tree and directory structures. Bridge Decouples an abstraction from its implementations so that they can vary independently. Example Database drivers / Printer drivers

Responsibility Patterns

Singleton Ensures a class has only a single instance… Resists the distribution of responsibility. Note Use a private constructor and create a method that calls it only once. Ensure the method is declared final. Example J2ME runtime class. Drivers that are responsible for controlling hardware. Observer Example JSlider.addChangeListener() Event passing in the model - view – controller (MVC) pattern Mediator Takes responsibility off several objects. Defines an object that encapsulates how a set of objects interacts. Note The attached objects being mediated are usually of different classes and often send events to the mediator. Defining the interfaces the pattern uses (lower diagram) seems wise. Example Accessing a database to reflect real world changes. Creating a GUI with lots of inter-related GUI components Proxy Provides a surrogate or placeholder for another object. Examples Image proxies – for while the true image is being downloaded Network resource proxys RMI / CORBA – for remote method invocation Dynamic proxies using JAVA reflection Defines a one to many dependency so when an object changes all its dependents are notified and update themselves automatically. Note In some cases a simplified subject allows only a single observer to be attached. Attempting to attach another will overwrite the first one or cause an exception to be thrown.

Chain of responsibility Avoids coupling the sender of a request to receiver. The request is passed along a chain until it reaches an object able to handle it. Example Parser chains to decode an input that could be in several formats. Thrown exceptions that travel up the call stack until they find a valid catch block. Customer support telephone networks. Traversing a composite (such as up a scene graph to find your position). Event handling in windows Visual C++. Flyweight Example String (in JAVA). Font information in a book. Uses sharing to support large numbers of fine grained objects efficiently. Multiple clients share the immutable part of an object.

Construction Patterns

Builder Separates construction of a complex object from its representation, so the same process can create different representations. Example JAVA StringBuilder class Parsers that take an input stream then use the information to build an object or representation. Factory Example Object.toString() in the JAVA Object interface The Iterator() method in the JAVA collection interface Threadpools Abstract factory The intent of abstract factory or kit is to allow the creation of families of related or dependent objects, without specifying their concrete classes. Example Creating user interface components with different look & feels by using UIManager and UI delegates. Prototype Provides objects by copying an example Example copy constructors Objects supporting the clone interface. Lets a class developer define an interface for creating an object while retaining control over which class to instantiate. Also lets a class defer initialisation to subclasses. Note A factory is also frequently used to isolate a client from having to manage the reuse of objects. Note JAVA Objects default clone() method produces a shallow copy not a deep copy. You may need to override this method to ensure the objects state information is replicated correctly.

Memento Without violating encapsulation, captures and externalizes an objects internal state so it can be restored to this state later. Example REDO and UNDO in applications. Saving and restoring a position in a game.

Operation Patterns

Template Defines an algorithm in an operation, deferring the definition of some steps so the subclass or other classes can supply them. Example Hooks Sorting collections (you supply the comparator method) State Example Sequencing complex GUIs (multi-input & multi-state) State-machines Strategy Encapsulates different approaches in separate classes that each implement a common operation Example Various sorting algorithms that use different sorting techniques but all implement a method called sort() that achieve the same result. Command Encapsulates a request as an object, allowing a user or service to determine when to evoke it, add parameters to a request, queue or log requests and support undoable operations. Example Menu items that allow an ActionListener to be attached, which implements ActionPerformed() if the menu item is triggered. Note To avoid unnecessary state creation, context usually holds all the state objects, and a context reference is passed to the state object which uses it to obtain the state objects and methods for updating the present state of the context. Note The above UML diagram shows a subclass with an overridden sub-method. Alternatively the sub-method could be passed in using the command design pattern Distributes state specific logic across classes that represent an objects state (encapsulating state logic into separate classes). The object appears to change its class whenever its state changes. Note In some cases a reference to the target is passed in as a parameter when the command is constructed, and is held within the command. The target often has an interface defined on which the command acts to achieve its functionality.

Interpreter Lets you compose executable objects according to a set of composition rules. Defines the representation of a language. Defers the creation of executable objects until runtime. Example BASIC, JAVA, CNC machine control programs Note Expressions can be run in a particular context (such as producing results in a particular window)

Extension Patterns

Decorator Attaches additional responsibilities, fields and method variations to an object at runtime. It is an alternative to sub classing for extending functionality. Example Buffered file writer Filters for streams iterator Example Collection iterators for (class element: collection) loops Composite iterators Visitor Lets you define a new method or methods without changing the classes on which they operate. Example Taxis – you call them, they visit you, then you use their public automobile and your cash to go out to a bar and have some fun. An iterator is an object that sequentially accesses the elements of another aggregated object without exposing its underlying representation. Note In the above UML concrete visitor calls accept on a targetObject. The targetObject then calls the appropriate visit method of the visitor passing a reference to itself. The visitor can then use public fields and methods of the targetObject or its own fields and methods to achieve what is desired.