Object Oriented Design David Talby. Welcome! n Introduction n UML u Use Case Diagrams u Interaction Diagrams u Class Diagrams n Design Patterns u Composite.

Slides:



Advertisements
Similar presentations
UML (Sequence Diagrams, Collaboration and State Chart Diagrams) Presentation By - SANDEEP REDDY CHEEDEPUDI (Student No: ) - VISHNU CHANDRADAS (Student.
Advertisements

Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
Unified Modeling Language
UML – Class Diagrams.
Irwin/McGraw-Hill Copyright © 2004 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS6th Edition.
Design Patterns David Talby. This Lecture Handle Synchronization & Events Observer Simplify Complex Interactions Mediator Change Behavior Dynamically.
© Copyright Eliyahu Brutman Programming Techniques Course.
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Design Patterns David Talby. This Lecture n What is it all about? n Abstract Factory n Composite n Strategy.
Chapter 3.4 Programming Fundamentals. 2 Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated.
Design Patterns David Talby. This Lecture n The rest of the pack u Working over a network F Proxy, State, Chain of Responsibility u Working with external.
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.
Composite Design Pattern. Motivation – Dynamic Structure.
Prepared by: Sanaz Helmi Hoda Akbari Zahra Ahmadi Sharif University of Tech. Summer 2006 An Introduction to.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
Slide 1 UML Review Chapter 2: Introduction to Object-Oriented Systems Analysis and Design with the Unified Modeling Language, Version 2.0 Alan Dennis,
Unified Modeling Language, Version 2.0
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Programming in Java Unit 3. Learning outcome:  LO2:Be able to design Java solutions  LO3:Be able to implement Java solutions Assessment criteria: 
1 UML Basic Training. UML Basic training2 Agenda  Definitions: requirements, design  Basics of Unified Modeling Language 1.4  SysML.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
ניתוח מערכות מידע 1 Unified Modeling Language (UML) § § The Unified Modeling Language (UML) is the industry-standard language for: Specifying, Visualizing,
An Introduction to the Unified Modeling Language
Introduction To OOP 1.0 Fundamentals Of Java Programming Language 2.0 Exception Handling 3.0 Classes, Inheritance And Polymorphism © 2011 | PN AZRINA.
Design Jon Walker. More UML ● What is UML again?
Logical view –show classes and objects Process view –models the executables Implementation view –Files, configuration and versions Deployment view –Physical.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Software Engineering Lecture 8 Object-Oriented Analysis.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
1 Technical & Business Writing (ENG-715) Muhammad Bilal Bashir UIIT, Rawalpindi.
Week 04 Object Oriented Analysis and Designing. What is a model? A model is quicker and easier to build A model can be used in simulations, to learn more.
1 Unified Modeling Language, Version 2.0 Chapter 2.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Chapter 3: Introducing the UML
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.
UML Course Instructor: Rizwana Noor. Overview  Modeling  What is UML?  Why UML?  UML Diagrams  Use Case  Components  Relationships  Notations.
Basic Characteristics of Object-Oriented Systems
Introduction to UML and Rational Rose UML - Unified Modeling Language Rational Rose 98 - a GUI tool to systematically develop software through the following.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
1 Design Object Oriented Solutions Object Oriented Analysis & Design Lecturer: Mr. Mohammed Elhajj
Slide 1 Unified Modeling Language, Version 2.0 Object-Oriented SAD.
Design Patterns David Talby. 11/20/2016Object Oriented Design Course2 Contents Representing Data Structures Composite Flyweight Decorator Traversing Data.
4/16/2018 Design Patterns David Talby.
Chapter 0: Introduction
Design Patterns: MORE Examples
Design Patterns: Brief Examples
The Movement To Objects
Systems Analysis and Design
Object-Oriented Analysis and Design
Systems Analysis and Design With UML 2
Unified Modeling Language
Systems Analysis and Design With UML 2
University of Central Florida COP 3330 Object Oriented Programming
Jim Fawcett CSE776 – Design Patterns Summer 2003
Unified Modeling Language
Chapter 20 Object-Oriented Analysis and Design
CIS 375 Bruce R. Maxim UM-Dearborn
Analysis models and design models
Software Design Lecture : 15.
Software Design Lecture : 14.
Object Oriented Design
Chapter 22 Object-Oriented Systems Analysis and Design and UML
CIS 375 Bruce R. Maxim UM-Dearborn
Presentation transcript:

Object Oriented Design David Talby

Welcome! n Introduction n UML u Use Case Diagrams u Interaction Diagrams u Class Diagrams n Design Patterns u Composite

UML n Unified Modeling Language u Standard for describing designs u Visual: a set of diagrams n Unifies entire design process: u Use Cases for requirements u Static class diagrams u Object & Interaction diagrams u Components, Packages, …

Use Cases n A Use case is a narrative document that describes the sequence of events of an actor using a system to complete a process. n A use case diagram visualizes relationships between a system’s use cases and actors

Use Case Document Name: Sell Item Initiator: Customer Type: Primary, Required Actions: 1. Customer asks for X 2. Sales clerk checks if X is in stock 3. … Error Case A: if … then …

Use Case Diagram n Actors participate in use cases n Use cases use or extend others

Use Case Diagram II

Sequence Diagrams n A sequence diagram visualizes an ordered interaction between objects, by showing the messages sent between them. n One way to start a design is: u Translating a UC to a sequence u Turn its actions to messages

A Sequence Diagram

Sequence Diagrams II n Good time-line visualization n Supports messages to self n Supports object of same class:

Sequence Diagrams III n Supports conditions and loops:

Collaboration Diagrams n Another visual way to show the same information that a sequence diagram shows n Uses numbering of messages instead of a timeline n Both diagrams are also called interaction diagrams

Collaboration Diagrams

n Good object-centric view n Identical to Sequence diagrams u Loops, conditions, arguments u Automatic translation possible

Class Diagrams n Class diagrams show the static picture of the system’s classes n And relationships between them

Diagramming a Class n All Additions are optional u Types and argument lists u Initial values and constants

Dependency n Class A requires B to compile u Creates it (Instantiates) u Gets an argument

Association n Class A points to a B object u Can be Uni- or Bi-Directional u Each role can be named

Aggregation n Class A contains a list of B’s u But B’s can exist without A’s u Can be Uni- or Bi-Directional u Can be numbered

Composition n Class A contains a list of B’s u B’s are destroyed with their container A is destroyed u Can be Uni/Bi-Di, Numbered

Inheritance n Class A inherits from class B

Numbering n Association, Aggregation and Composition can constraint lists

Templates & Interfaces T n Both are supported

Stereotypes n Attributes of classes or methods u Standard: Interface, Abstract u Can be project-specific

Package Diagrams n Organize a system’s elements into related groups to minimize dependencies between them n Provides a high-level view n A UML package is analogous to u a Java package u a C++ namespace

Package Diagrams II

Package Diagrams III

UML Notes n Can be attached to anything T

Other UML Diagrams n State diagrams illustrate the states of a system or an object, and events that cause state transitions n Component diagrams show compiler and runtime dependencies between components. n Deployment diagrams show the distribution of processes and components to processing nodes. n UML is a large standard

Design Patterns n O-O Design is Hard n Errors are expensive n Reuse experts’ designs n Pattern = Documented experience

Expected Benefits n Finding the right classes n Finding them faster n Common design jargon n Consistent format n Coded infrastructures

O-O Programming n An interface is a contract to clients. n A class implements interface(s). n Objects are instances of classes. n Objects are only accessed through their public interfaces. n Only two relations between classes: Inheritance and composition

Object Relationships n Inheritance: Static and efficient, but exposes and couples modules n Composition: Hides more from client and can change dynamically n Gang of Four: “Favor composition over inheritance” n Dijkstra: “Most problems in computer science can be solved by another level of indirection”.

Designing for Change n The Open-Closed Principle n The Single-Choice Principle n Non-clairvoyance n Key Issue: Prepare for change! n Well, prepare for what?

Causes of Redesign n Dependence on hardware or software platform n Dependence on representation or implementation n Specifying a class upon creation n Algorithmic dependence n Tight coupling n Overuse of inheritance n Inability to alter classes easily

Pattern Categories n Creational - Replace explicit creation problems, prevent platform dependencies n Structural - Handle unchangeable classes, lower coupling and offer alternatives to inheritance n Behavioral - Hide implementation, hides algorithms, allows easy and dynamic configuration of objects

Pattern of Patterns n Encapsulate the varying aspect n Interfaces n Inheritance describes variants n Composition allows a dynamic choice between variants Criteria for success: Open-Closed Principle Single Choice Principle

1. Composite n A program must treat simple and complex objects uniformly n For example, a painting program has simple objects (lines, circles and texts) as well as composite ones (wheel = circle + six lines).

The Requirements n Treat simple and complex objects uniformly in code - move, erase, rotate and set color work on all n Some composite objects are defined statically (wheels), while others dynamically (user selection) n Composite objects can be made of other composite objects n We need a smart data structure

The Solution n All simple objects inherit from a common interface, say Graphic: class Graphic { void move(int x, int y) = 0; void setColor(Color c) = 0; void rotate( double angle ) = 0; } n The classes Line, Circle and others inherit Graphic and add specific features (radius, length, etc.)

The Solution II n This new class inherits it as well: class CompositeGraphic : public Graphic, public list { void rotate(double angle) { for (int i=0; i<count(); i++) item(i)->rotate(); }

The Solution III n Since a CompositeGraphic is a list, it had add(), remove() and count() methods n Since it is also a Graphic, it has rotate(), move() and setColor() too n Such operations on a composite object work using a ‘forall’ loop n Works even when a composite holds other composites - results in a tree-like data structure

The Solution IV n Example of creating a composite: CompositeGraphic *cg; cg = new CompositeGraphic(); cg->add(new Line(0,0,100,100)); cg->add(new Circle(50,50,100)); cg->add(t); // dynamic text graphic cg->remove(2); n Can keep order of inserted items if the program needs it

The GoF UML n Single Inheritance n Root has add(), remove() methods

The Fine Print n Sometimes useful to let objects hold a pointer to their parent n A composite may cache data about its children (count is an example) n Make composites responsible for deleting their children n Beware of circles in the graph! n Any data structure to hold children will do (list, array, hashtable, etc.)

Known Uses n In almost all O-O systems n Document editing programs n GUI (a form is a composite widget) n Compiler parse trees (a function is composed of simpler statements or function calls, same for modules) n Financial assets can be simple (stocks, options) or a composite portfolio

Pattern of Patterns n Encapsulate the varying aspect n Interfaces n Inheritance describes variants n Composition allows a dynamic choice between variants Criteria for success: Open-Closed Principle Single Choice Principle