SE2811 Software Component Design Dr. Rob Hasker

Slides:



Advertisements
Similar presentations
Inheritance Inheritance Reserved word protected Reserved word super
Advertisements

OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Course Instructor: Aisha Azeem
Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns.
Object Oriented Analysis and Design Introduction.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
Introduction To System Analysis and Design
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Computer Science Topical Paper Presentation #03 Adam Coffman The Cascading Bridge C a s c a d i n g B r i d g e – P a g e 1 The Cascading Bridge.
Slide design: Dr. Mark L. Hornick
Tutorial 4 IT323.  Q1. As a software project manager in a company that specializes in the development of software for the offshore oil industry, you.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Chapter 0: Introduction
Design Patterns: MORE Examples
Chapter 5 – Design and Implementation
The Movement To Objects
Chapter 5:Design Patterns
CSC 221: Computer Programming I Spring 2010
A Brief Introduction to Design Patterns
Introduction to Design Patterns
Chapter 11 Object-Oriented Design
CSC 221: Computer Programming I Fall 2005
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Week 10: Object Modeling (1)Use Case Model
UNIT 3 – LESSON 5 Creating Functions.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
The Object-Oriented Thought Process Chapter 06
Interfaces and Inheritance
Chapter 6: Using Design Patterns
Software Engineering (CSI 321)
SE-2811 Software Component Design
Creating and Using Classes
7. Decorator, Façade Patterns
1. Where to start SE2811 Software Component Design Dr. Josiah Yoder
The Object-Oriented Thought Process Chapter 05
Software Engineering Lecture #8.
Slides by Steve Armstrong LeTourneau University Longview, TX
Chapter 20 Object-Oriented Analysis and Design
Object Oriented Practices
Need for the subject.
SYS466 Domain Classes – Part 1.
Chapter 5 Architectural Design.
An Introduction to Software Architecture
DESIGN PATTERNS : Strategy Pattern
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Introduction to Design Patterns
Adapter Design Pattern
7. Decorator, Façade Patterns
8. Observer Pattern SE2811 Software Component Design
14. Factory Pattern SE2811 Software Component Design
4: Object-oriented Analysis & Design
SE2811 Software Component Design Dr. Rob Hasker
10. Façade Pattern SE2811 Software Component Design
14. Factory Pattern SE2811 Software Component Design
Applying Use Cases (Chapters 25,26)
Chapter 5 Architectural Design.
Computational Thinking
System Reengineering Restructuring or rewriting part or all of a system without changing its functionality Applicable when some (but not all) subsystems.
Use Case Analysis – continued
Chapter 8, Design Patterns Introduction
16. Visitors SE2811 Software Component Design
SE2811 Software Component Design Dr. Rob Hasker
Presentation transcript:

SE2811 Software Component Design Dr. Rob Hasker 19q2: 1-2,4,6-12,14-15 2. Adapter

Null Object Pattern, revisited Recall UML notation: 0..1: StereoController has 0 or 1 Equalizers StereoController has reference to a Volume object Implied multiplicity: 1 Drop role name if obvious Not documenting constructors; little additional information Don’t list attribute if have association Minimal clutter! A significant part of the course: identify problems and solve those problems using (design) patterns

Null Object Pattern, revisited What problem was being solved? How to apply to RealClass? Solution Define interface Create null object version with do- nothing operations Benefits? Drawbacks? A significant part of the course: identify problems and solve those problems using (design) patterns

Design Patterns Generally: solving maintenance problems Each pattern: Course goal: make maintenance easier Why? Each pattern: Problem statement: what problem is being solved How maintenance improved Name: allows communication Solution: class design: Relationships and Behavior Advantages – what is improved in the design Shortcomings – negatives of using the pattern Reusing approaches, not specific code or algorithms Why? Successful systems get used, used systems result in requests for changes.

Pattern #2 Scenario: System built around a class by Vendor1 Purchased when build application Vendor1 goes out of business, and you need an update Existing System Vendor1 Class Vendor1 interface

Original Configuration Vendor2: similar class, but new interface Change all the calls to methodA, etc? Assumption: ClientApp is heavily dependent on ServiceProvider many calls to various ServiceProvider methods. Commonly, ServiceProvider implements numerous methods (more than shown here) Issue: it’s often not just the method names, but rules on the order they were applied

Solution: Adapter (Wrapper) Pattern Implements the interface your classes expect Uses the vendor interface to service your requests. Existing System Vendor2 Class Existing System Vendor2 Class Adapter

Applying Adapter 2. An interface declaring the same methods as the original ServiceProvider is created. 3. A replacement class for the original similar functionality but with a Different set of methods – the adaptee 1. The original ServiceProvider class is obsolete and discarded new methods

The Adapter Pattern features Note client calls original method That method delegates to the new service provider Typically: the implementation of methodA will be short simply call one or two methods in NewServiceProvider However, may have a complex interface may need to construct additional information Example: making a 3-D character move on a screen Result from adaptee: must translate back to the results expected by the client Only change to the client: create instance of the adapter (rather than the original vendor class)

Example: lighting a room Delivered system: What to do if replace Lamp by BetterLamp?

When to use Adapter Legacy code which interfaces to a class library that has changed Changes might include versions, vendors, new requirements New application Interfaces with known third-party library That library not yet defined Isolate the problem! Define an interface, write the adapter later

Adapter: a structural design pattern Captures relationships between classes Reduces the dependencies between classes Traditional solution: rewrite existing code to meet new need What if we need the original code for another system? Clone the code? When copy/paste is your design strategy, you’ve lost Don’t repeat yourself (DRY), again!

Adapter as a design pattern What is an alternative name? Wrapper When to apply? That is, what problem is being solved? Describe the application to a neighbor (in generic terms) Draw a class diagram! What are the advantages? What are the shortcomings? Not: more classes – we’ve only introduced a couple; lost in the noise All patterns introduce new classes; only significant if create large numbers Overhead for delegation calls It’s less obvious what an adapter method call does The “more classes” is always true and uninteresting unless it is a LOT more classes

What we’ve accomplished The Adapter pattern has solved a big issue: how to disassociate two pieces of code that are likely to change Our goal: isolate components that change Question: should we always use an interface class? Why might we want an abstract class instead? abstract classes: allow non-final fields, concrete methods

Application Working in teams of two, apply the adapter pattern to a queue: Download se2811/samples/SimpleLinkedList.java Download se2811/samples/SimpleQueue.java Use IntelliJ to build, run both Download se2811/samples/GenericQueue.java Create LinkedQueue.java with the same test main as SimpleQueue.java but using SimpleLinkedList instead of ArrayList. If instructed, upload LinkedQueue.java to Blackboard.

Review Design patterns Null Object Pattern, revisited Adapter: adapt existing software to new classes Provide flexibility if don’t have details for a critical class early in the project