CompSci 280 S Introduction to Software Development

Slides:



Advertisements
Similar presentations
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Advertisements

7M822 UML Class Diagrams 7 October 2010.
Stereotypes Stereotypes provide the capability to create a new kind of modeling element. –They can be used to classify or mark modeling elements. –A type.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System modeling 2.
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
Object-Oriented Analysis and Design
7M701 1 Software Engineering Object-oriented Design Sommerville, Ian (2001) Software Engineering, 6 th edition: Chapter 12 )
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 8 Slide 1 System models.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
Design Patterns in Java Appendix D UML at a Glance Summary prepared by Kirk Scott 1.
©Ian Sommerville 2006Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
Modified from Sommerville’s originalsSoftware Engineering, 7th edition. Chapter 8 Slide 1 System models.
7M822 UML Class Diagrams advanced concepts 15 September 2008.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions of systems whose requirements are being.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions of systems whose requirements are being.
UML Diagrams: Class Diagrams The Static Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Lab 04.
CS3773 Software Engineering Lecture 04 UML Class Diagram.
Software Engineering, 8th edition Chapter 8 1 Courtesy: ©Ian Somerville 2006 April 06 th, 2009 Lecture # 13 System models.
Sommerville 2004,Mejia-Alvarez 2009Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
Unit 1 INTRODUCTION TO MODELING AND CLASS MODEL Ref : L7-UML.PDF.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 Chapter 7 System Models.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
UML The Unified Modeling Language A Practical Introduction Al-Ayham Saleh Aleppo University
Design Model Lecture p6 T120B pavasario sem.
Object Oriented Analysis: Associations. 2 Object Oriented Modeling BUAD/American University Class Relationships u Classes have relationships between each.
Object Oriented Analysis and Design Class and Object Diagrams.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
Class Diagram Chapter 21 Applying UML and Patterns Craig Larman.
CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
Class Diagram Lecture # 1. Class diagram A Class Diagram is a diagram describing the structure of a system shows the system's classes Attributes operations.
Object Oriented Programming and Data Abstraction Earl Huff Rowan University.
UML Fundamental Elements. Structural Elements Represent abstractions in our system. Elements that encapsulate the system's set of behaviors. Structural.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Engineering, 7th edition. Chapter 8 Slide 1 System models.
CompSci 280 S Introduction to Software Development
Chapter 12 – Object-Oriented Design
Design Review.
CHAPTER
UML Diagrams: Class Diagrams The Static Analysis Model
Business System Development
Chapter 5: Structural Modeling
Object-Oriented Analysis and Design
Class Diagrams.
The Object-Oriented Thought Process Chapter 1
Today’s Objectives Define the Problem Domain
System Modeling Chapter 4
Abstract descriptions of systems whose requirements are being analysed
OBJECT RELATIONSHIPS, ATTRIBUTES, AND METHODS
Software Engineering System Modeling Chapter 5 (Part 2) Dr.Doaa Sami
Creating and Using Classes
Object-Oriented Analysis
Object Oriented Analysis and Design
Domain Class Diagram Chapter 4 Part 2 pp
Lec 3: Object-Oriented Data Modeling
Software Engineering Lecture #11.
Systems Analysis and Design With UML 2
UML Class Diagram.
Software Engineering System Modeling Extra examples Dr.Doaa Sami
Understand and Use Object Oriented Methods
Copyright 2007 Oxford Consulting, Ltd
Class Diagrams Class diagram is basically a graphical representation of the static view of the system and represents different aspects of the application.
Domain Modeling.
Object Oriented System Design Class Diagrams
Information System Design
Chapter 4 System Modeling.
Information system analysis and design
Presentation transcript:

CompSci 280 S2 2107 Introduction to Software Development Class Diagrams

Today’s Agenda Topics: Reading: Introduction Class Diagrams Relationships Associations Generalization Aggregation Class Diagram Examples How to build a class diagram Reading: Software Engineering 10th Edition, Ian Somerville Chapter 5 Fowler, Martin, UML distilled : a brief guide to the standard object modeling language, Third Edition, Boston : Addison-Wesley, c2004 – Chapter 9 Lecture08

1.Introduction Structural models Structural models of software display the organization of a system in terms of the components that make up that system and their relationships. Structural models may be static models, which show the structure of the system design. Class diagrams are used when developing an object-oriented system model to show the classes in a system and the associations between these classes. An object class can be thought of as a general definition of one kind of system object. An association is a link between classes that indicates that there is some relationship between these classes. Lecture08

2.Class diagrams Steps: Identifying Classes Specifying Attributes Identify classes by examining the problem statement or by performing a “Grammatical Parse” on the use-cases UML class notation is a rectangle divided into three parts: class name, attributes, and operations. write <<interface>> on top of interfaces' names use italics for an abstract class name Specifying Attributes should include all fields of the object Defining operations Super … Generalisation Attribute1: type Sub1 Operation1() Operation2(): type Sub2 Pieces 1 0..* Associated Association Aggregation Lecture08

2.Class diagrams Classes A description of a group of objects all with similar roles in the system Structural features define what objects of the class know Behavioral features define what objects of the class can do Identifying object classes is often a difficult part of object oriented design. There is no 'magic formula' for object identification. It relies on the skill, experience and domain knowledge of system designers. Object identification is an iterative process. You are unlikely to get it right first time. Approaches Use a grammatical approach based on a natural language description of the system. Base the identification on tangible things in the application domain. Use a behavioural approach and identify objects based on what participates in what behaviour. Use a scenario-based analysis. The objects, attributes and methods in each scenario are identified. Lecture08

2.Class diagrams Specifying Attributes Attributes (fields/instance variables) are the set of data objects that fully define the class within the context of the problem. i.e. represent the state of an object of the class To develop attributes for class, can study use-case and select those “things” that reasonably “Belong” to the class. Static members are underlined. Instance members are not. Access specifiers appear in front of each member. Private (-): can be used only by the owning class Protected (#): can be used by the owing class and descendents of the class Public (+): can be used by any other class Package/default (~) Default value: the value for a newly created object if the attribute isn't specified during creation #ID: int #Name: String #Password: String Person <access specifier> <name> : <type> <multiplicity> = <default> Lecture08

2.Class diagrams Defining operations Operations define the behavior of an object. Operations are descriptions of behavioral or dynamic features of a class Four broad categories: Operations that manipulate data in some way, perform a computation, inquire about the state of an object, monitor an object for the occurrence of the controlling event. To derive a set of operations, study a use-case( or narrative) and select those operations that reasonably belongs. The parameter list shows each parameter type preceded by a colon. Access specifiers appear in front of each member. Return-type: the type of the returned value <access specifier> <name> ( <parameter list>) : <return type> -date: String -returned: boolean … Rental +rent(customerID, videoID): boolean +return(customerID, videoID): boolean Lecture08

2.Class diagrams Examples Lecture08

3.Relationship: Association A relationship between instances of the two classes. There is an association between two classes if an instance of one class must know about the other in order to perform its work. e.g. Passing messages and receiving responses In a diagram, an association is a solid line connecting two classes. A navigability arrow on an association shows which direction the association can be traversed or queried. Multiplicity of Associations Specifies how many instances of one class may relate to a single association Lecture08

3.Association Multiplicity Multiplicity specifies how many objects an instance of the class at the other end of the association can be linked to. 1..*: 1-to-many e.g A RectangleList has many rectangles 1-to-1 e.g. each student must carry exactly one ID card 0..1 zero or one 0..* / * Zero or more 1 exactly one 1..* One or more 2..4 Specified range Lecture08

3.Association Connecting the Classes: Associations Note: Connect classes with a line Specify multiplicities on each side of association: min..max (min and max of connected instances on each side) Use roles to make the model more self-explanatory A lecturer teaches an arbitrary number of courses (possibly none) 1..* 0..* 0..* 1 coordinator participant A course is taken by one or more students (the participants) A student can take an arbitrarily number of courses (possibly none) A course has exactly one coordinator Lecture08

3.Association Classes and associations in the MHC-PMS Lecture08

4.Relationships: Generalization Generalization: an inheritance link indicating one class is a superclass (the more general) of the child class/subclass (the more specific element) i.e. is-a relationship An inheritance link indicating one class is a superclass of the other. A generalization has a triangle pointing to the superclass. Checking Generalizations If class A is a generalization of a class B, then “Every B is an A” Lecture08

4.Generalization Reusing Classes “Is-a”-relation (inheritance) Lecture08

4.Generalization A generalization hierarchy Lecture08

4.Generalization Generalization In modeling systems, it is often useful to examine the classes in a system to see if there is scope for generalization. If changes are proposed, then you do not have to look at all classes in the system to see if they are affected by the change. In object-oriented languages, such as Java, generalization is implemented using the class inheritance mechanisms built into the language. In a generalization, the attributes and operations associated with higher-level classes are also associated with the lower-level classes. The lower-level classes are subclasses inherit the attributes and operations from their superclasses. These lower-level classes then add more specific attributes and operations. Advantages: Treating similar objects similarly Reuse of commonalities of classes Better maintenance Lecture08

5.Relationships: Aggregation An aggregation model shows how classes that are collections are composed of other classes. Aggregation models are similar to the part-of relationship in semantic data models. (i.e. has-a relationship) An aggregation has a diamond end pointing to the part containing the whole. Normal Aggregation: Represented by a line with a hollow diamond Composition (strong aggregation), a Part cannot exist once Whole is destroyed Represented by a line with a filled black diamond Lecture08

5.Aggregation Example Composition Vs Aggregation If we remove the MovieTheater, we also move the box office (composition), but movies may still exist (aggregation) Lecture08

6.Class Diagram Example A customer can have any number of orders -date: String -status: String Order +calcTotal() +calcTotalWeight -address: String -phone: String Customer 1 0..* An order has a collection of OrderDetails An order belongs to one customer 1 Aggregation 1..* -quantity: int -taxStatus: String OrderDetail +calcSubTotal() +calcWeight() -shippingWeight: double -description: String … Item +getWeight() +getPriceForQuantity 1 0..* An OrderDetail can be queried about its Item, but not the other way around. Lecture08

6.Class Diagram Example Lecture08

7.How to build a class diagram Design is driven by criterion of completeness either of data or responsibility Data Driven Design identifies all the data and see it is covered by some collection of objects of the classes of the system Responsibility Driven Design identifies all the responsibilities of the system and see they are covered by a collection of objects of the classes of the system Noun identification Identify noun phrases: look at the use cases and identify a noun phrase. Do this systematically and do not eliminate possibilities Eliminate inappropriate candidates: those which are redundant, vague, outside system scope, an attribute of the system, etc. Validate the model… Lecture08

Exercise: ATM Machine Identifying Classes So far: we know basic requirements for system. Now want to specify basics of how system works: identify the data & functions for a system group these into appropriate objects determine object inter-relationships: both “data” relationships & “behavioural” relationships In full system development, also develop set of “non-functional requirements” Steps: work from data/functions in English requirements or use case definitions group them into objects (often takes several goes!!!) Common approach: nouns = attributes/objects, verbs = functions... I find it easiest to work from data/functions in English requirements or use case definitions group them into objects (often takes several goes!!!) find focusing on data aspects of objects (“entities”) then adding functions works best Common approach: nouns = attributes/objects, verbs = functions... Lecture08

Step 1: Identify the data & functions for a system from use cases: Grouped closely-related attributes -> entities Grouped functions by data they act on Complete the following: Tips: DON’T get carried away with objects for user/device interfaces, databases, data structures, etc. - these are DESIGN, not analysis We want to capture the “essence” of the system i.e. important data/functions Customer Account ATM Transaction Bank Lecture08

Step 2: Determine inter-object relationships: Draw UML Class Diagrams for system structure Tips: Now: how are the objects related??? Three main ways: 1. generalisation e.g. staff -> person 2. association e.g. customer -> account 3. aggregation e.g. account -> transaction Lecture08

Step 3: Multiplicity Association #1 (“data”): customer has 1 or 2 accounts account has bunch of transactions each transaction is made from 1 account Lecture08