Design Patterns Part 1: Observer, Singleton, & Adapter

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

The Observer Pattern SE-2811 Dr. Mark L. Hornick 1.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Online accounts management for small businesses By Wagner Silva – – Abstract: This project demonstrates the steps taken.
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
Chapter 9 Problems TC 1, 2. TC 1 Solution is to create an adapter that adapts calls from the payroll system to the payroll tax subsystem. TaxCalcAdapter.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Design Patterns.
Observer Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
CSSE 374: 3½ Gang of Four Design Patterns These slides derived from Steve Chenoweth, Shawn Bohner, Curt Clifton, and others involved in delivering 374.
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
Using AOP to Ease Evolution Presented by David Shepherd (QLI & UD) Co-Authors: Thomas Roper (QLI) and Lori Pollock (UD)
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
More Design Patterns Horstmann ch.10.1,10.4. Design patterns Structural design patterns –Adapter –Composite –Decorator –Proxy Behavioral design patterns.
Chapter 18 The Observer Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
 Registry itself is easy and straightforward in implementation  The objects of registry are actually complicated to store and manage  Objects of Registry.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
By : SAG3 Members.  Cross platform client interface for Time recording/capturing  MS Project integration to Time tracker  integration to Time.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
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.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
CDLC E-Form Use the CDLC e-form to request from libraries outside Questar III SLS or if Questar III libraries do not have what you are looking for.
Slide design: Dr. Mark L. Hornick
START Application Spencer Johnson Jonathan Barella Cohner Marker.
Managing multiple projects or services? Have a mix of Microsoft Project and more simple tasks? Need better visibility and control?
Programming with Patterns Jeremy Cronan Alliance Safety Council
Observer Pattern Context:
SYSTEM ANALYSIS & DESIGN SYED MD MARUF HASAN TP030777
Save Time Managing your Team. Communicate Better.
Design Patterns: Brief Examples
Structure of a web application
Welcome to the world of CRISIS COMMANDER
Slide design: Dr. Mark L. Hornick
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Viewbiquity HTML5 Tom Shafron Developer’s Blog CEO, Viewbiquity
Introduction to Design Patterns
Delegates and Events 14: Delegates and Events
Introduction with a few design patterns
Design Patterns Part 2: Builder & Memento
INFOD-WG Implementation
Design Patterns with C# (and Food!)
Checkout and Electronic Payment Processing
Offline Database Synchronization with SOAP and MySQL
NewTrackerTM Demo.
Adapter Pattern 1.
Observer Pattern 1.
Review: Design Pattern Structure
Design Patterns Part 2: Factory, Builder, & Memento
Bridging the Gap Between Technology and Business
Design Patterns Lecture part 1.
OBJECT ARCHITECTURE DESIGN
Adapter Design Pattern
8. Observer Pattern SE2811 Software Component Design
Week 6, Class 2: Observer Pattern
Chapter 8, Design Patterns Introduction
Adapter Pattern Jim Fawcett
Software Engineering and Architecture
Adapter Pattern Jim Fawcett
Presentation transcript:

Design Patterns Part 1: Observer, Singleton, & Adapter

Learning Objectives Design patterns: what & why When and how to apply Familiarity with several popular patterns: Observer Singleton Adapter

What is a Design Pattern? Template solutions to common problems Benefits: Avoid re-inventing solutions Promotes software quality Reusability, maintainability, etc. Facilitate communication

Running Example: Tiger Dining

Tiger Dining Web App

Design problem: Email notification

Chef’s view

Manager’s view: To see subscribed users

How to connect? Orders Email notification

OrdersController new() create() … EmailNotifier order_notification() ?

Solution: Observer Pattern Subject attach(observer) detach(observer) notify() Observer update() observes * Needs to add an observer for the food order activity Define one-to-many dependency

order_notification() update() Subject attach(observer) detach(observer) notify() Observer update() observes * OrdersController new() create() add_observer() notify_observers() EmailNotifier order_notification() update() observes *

Control Flow OrdersController Order EmailNotifier create save notify_observers Left to right update Send Email

Goal: Implement Observer pattern Modify OrdersController (Subject) include “Observable” adds observer using “add_observer” Uses “notify_observers” Modify EmailNotifier (Observer) Observer has “update” method Add code snippet

Goal: Implement Observer pattern

Goal: Implement Observer pattern

Other Examples Spreadsheet Employee payroll GUI program (callback)

Classroom Activity

Design problem: Sales Logging

Problem Saves records of transactions as backup Sales logging for transaction failure

SalesLogger initialize(file) formatter log(message)

Solution: Singleton Single file to log all the sales information Easy to look up Singleton inst: Singleton instance(): Singleton … if inst == nil inst = Singleton.new end return inst

Making class Singleton Steps of making a class Singleton: Creating the class variable @@instance Initializing it with the single instance @@instance = SimpleLogger.new Creating the class level instance method Making a new private

Goal: Implement Singleton pattern SalesLogger class include “Singleton” SalesController call instance call log(message)

Goal: Implement Singleton pattern

Singleton Examples In Rails: Outside Rails: development.log test.log Webrick in rake Outside Rails: tomcat ant

Design problem: New Payment method

Goal: To Add Visa Debit Card and Paypal

Goal: To add VisaPay PaymentsController new create … DiningDollars charge(uid) …

Solution: Adapter Interface which bridge a gap in payment methods Key objects are Target, Adapter and Adaptee Target Request() Client Adapter Request() Adaptee SpecificRequest()

DiningDollarsAdapter PaymentProcessor process_payment() PaymentsController DiningDollarsAdapter process_payment() VisaPayAdapter process_payment() … DiningDollars charge(uid) VisaPay pay(debitcard, cvv, exp) …

Visa processes the payment Control Flow PaymentsController VisaPayAdapter VisaPay create process_payment pay Visa processes the payment

Goal: Implement Adapter Pattern PaymentsController “create” method call the adapter based on the input type VisaPayAdapter defines “process_payments” inherited from the PaymentProcessor VisaPay defines pay(creditcard, cvv, exp) saves the information

Adapter: Example in Rails Active Records Contains adapters for several databases (PostgreSQL or MySQL) Wraps them up in common interface AbstractAdapter implements common functionality PostgreSQLAdapter AbstractMysqlAdapter

Summary Singleton: Observer: Adapter: Making Sure There Is Only one Keeping Up with the Times Adapter: Filling the gaps

Practice Quiz