CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

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.
Chapter 2: The Observer Pattern. Consider the Following Application Application specification Humidity Temperature Pressure Weather Station Weather Data.
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
Plab – Tirgul 12 Design Patterns
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Winter 2007ACS-3913 Ron McFadyen1 Observer Pattern Problem: There are many objects (observers / subscribers) needing to know of the state changes, or events,
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.
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.
CS 210 Introduction to Design Patterns September 7 th, 2006.
Observer Behavioral Pattern. Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified.
Programming in C# Observer Design Pattern
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
DAAD project “Joint Course on OOP using Java” On Object Oriented modeling in Java (Why & How) Ana Madevska Bogdanova Institute of informatics Faculty of.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
ECE450S – Software Engineering II
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
The Observer Pattern.
CS 210 Review October 3, 2006.
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.
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:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Object-Orientated Analysis, Design and Programming
Design Patterns: MORE Examples
COMP2110 Software Design in lecture 14 Patterns(1) /Detailed Design
Software Architecture & Difference from Design
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
CS 153: Concepts of Compiler Design August 29 Class Meeting
Introduction to Design Patterns
Chapter Nine The Strategy Pattern
Design Patterns Introduction
Observer Design Pattern
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Presented by Igor Ivković
OO Design - Observer Pattern
Advanced Programming Behnam Hatami Fall 2017.
Web Programming Language
CSSSPEC6 SOFTWARE DEVELOPMENT WITH QUALITY ASSURANCE
CMPE 152: Compiler Design August 23 Class Meeting
CS 350 – Software Design An Introduction to Design Patterns – Chapter 5 A proposition behind design patterns is that quality of software systems can be.
DESIGN PATTERNS : Introduction
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Design Patterns Lecture part 1.
CMPE 152: Compiler Design January 29 Class Meeting
A (partial) blueprint for dealing with change
Chapter 8, Design Patterns Introduction
Presented by Igor Ivković
Object Oriented Design & Analysis
Software Design Lecture : 27.
CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting
Presentation transcript:

CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Review Object-oriented design basics Object-oriented design principles Abstraction Encapsulation Inheritance Polymorphism Object-oriented design principles Encapsulate what varies. Favor composition over inheritance. Program to interfaces, not to implementations.

Other Principles Open-Closed Principle (OCP) Classes should be open for extension but closed for modification. Don’t Repeat Yourself (DRY) Principle Abstract out things that are common and place them in a single location. Single Responsibility Principle (SRP) Make every object cohesive by giving it a single responsibility that all its services should focus on carrying out.

Other Principles, cont’d The Liskov Substitution Principle (LSP) Any object should be substitutable by an object of its base (super) class. To maintain the LSP in your code, use delegation, composition, or aggregation instead of inheritance. Code reuse Use delegation, composition, and aggregation to use behavior from other classes.

Goal: Better Software! Well designed Results Implement object-oriented design basics. Follow object-oriented design principles. Results More reliable software done sooner. Flexible enough to handle change. Easy to maintain. It’s time to move up to an even higher level.

Design Patterns A general reusable solution to a commonly occurring software design problem. A template for how to solve a problem that can be used in many different situations. Formalized best practices that can be used to solve common software design problems. A shared vocabulary for discussing solutions to software design problems.

Design Patterns, cont’d Not cut and paste code that can be inserted into an application. Discovered, not created from scratch. Found after many years of real-world programming experience by many top programmers. Originated as a concept for designing buildings by architect Christopher Alexander. Popularized in computer science by the “Gang of Four” (GOF) and their design patterns book.

Shared Pattern Vocabulary Powerful A design pattern communicates not just its name, but the entire set of its qualities, characteristics, and constraints. Say more with less Describe a design pattern and other developers quickly know precisely the design you have in mind. Stay “in the design” longer Design pattern discussions stay at a high level without diving into implementation details.

Shared Pattern Vocabulary, cont’d Accelerate the design team A team well versed in design patterns can move more quickly with fewer misunderstandings. Accelerate junior programmers Senior programmers who use design patterns serve as strong role models for junior programmers.

How to Use Design Patterns Unlike library code that gets inserted into your code, design patterns go into your brain. Framework and library code provide specific implementations of solutions. Design patterns are at a higher level. They tell us how to structure classes to solve certain software design problems. We must adapt the design patterns to fit each application.

The Strategy Pattern We used the Strategy Design Pattern to create the SimUDuck application.

The Strategy Pattern, cont’d Define a family of algorithms. Encapsulate each algorithm. Make them interchangeable within the family. Vary which algorithm to use independently from the clients that use it. https://en.wikipedia.org/wiki/Strategy_pattern

Example: Weather Monitoring Station WeatherData object tracks current conditions temperature, humidity, barometric pressure An app must provide three display elements updated in real time as the WeatherData object obtains the most recent measurements: current conditions weather statistics simple forecast Design an API for developers to create their own weather displays. This example and its images are from Head First Design Patterns by Eric & Elizabeth Freeman O’Reilly, 2004

Weather Monitoring Station, cont’d

Obtaining Weather Data

First Implementation

First Implementation: What’s Wrong

Newspaper Subscriptions A newspaper publisher goes into business and begins publishing newspapers. You subscribe to a particular publisher, and every time there’s a new edition it gets delivered to you. As long as you remain a subscriber, you get new newspapers. You unsubscribe when you don’t want papers anymore, and they stop being delivered. While the publisher remains in business, people, hotels, airlines, and other businesses constantly subscribe and unsubscribe to the newspaper.

Publishers + Subscribers = Observer Pattern Observer objects can come and go.

Observer Pattern Defined Define a one-to-many dependency between objects. When one object changes state, all of its dependents are notified and updated automatically.

Observer Pattern UML

Loose Coupling All the subject knows about an observer is that it implements the Observer interface. The subject doesn’t care who the observer is or what it does with the data the subject provides. We can add new observers at any time. We never need to modify the subject to add new types of observers. We can reuse subjects or observers independently of each other. Changes to either the subject or an observer will not affect the other.

Weather Station Design

Weather Station Implementation

WeatherData Implementation

Display Elements Implementation

Observer Pattern Summary Design principle: Separate what varies from what stays the same. What varies: The state of the subject and the number and types of observers. Design principle: Program to an interface, not to an implementation. Both the subject and the observer use interfaces. The subject keeps track of objects that implement the Observer interface. Observers register and are notified by the Subject interface.

Observer Pattern Summary, cont’d Design principle: Favor composition over inheritance. The Observer Pattern composes any number of observers with their subjects. These relationships are not part of an inheritance hierarchy. They are established at run time by composition.