Object Oriented Modelling Class & Object Models. Analysis V. Design There is no significant distinction between the techniques used during Analysis and.

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

Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
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
2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Introduction To System Analysis and Design
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 8 Slide 1 System models.
UML Class Diagram and Packages Written by Zvika Gutterman Adam Carmi.
Slide 1 Systems Analysis & Design CS183 Spring Semester 2008 Dr. Jonathan Y. Clark Course Website:
Slide 1 Chapter 7 Structural Modeling. Slide 2 Key Ideas A structural or conceptual model describes the structure of the data that supports the business.
Lecture 4 Class Responsibility Collaboration Cards
Class Diagram & Object Diagram
Modified from Sommerville’s originalsSoftware Engineering, 7th edition. Chapter 8 Slide 1 System models.
© Copyright Eliyahu Brutman Programming Techniques Course.
7M822 UML Class Diagrams advanced concepts 15 September 2008.
Sharif University of Technology Session # 7.  Contents  Systems Analysis and Design  Planning the approach  Asking questions and collecting data 
PRJ566: PROJECT PLANNING AND MANAGEMENT Class Diagrams.
UML Class Diagrams: Basic Concepts. Objects –The purpose of class modeling is to describe objects. –An object is a concept, abstraction or thing that.
Object-Oriented Analysis and Design
UML Diagrams Computer Science I.
Introduction To System Analysis and design
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions of systems whose requirements are being.
Chapter 4 System Models A description of the various models that can be used to specify software systems.
System models Abstract descriptions of systems whose requirements are being analysed Abstract descriptions of systems whose requirements are being analysed.
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.
UML Diagrams: Class Diagrams The Static Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
©Ian Sommerville 1995/2000 (Modified by Spiros Mancoridis 1999) Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions.
Programming in Java Unit 3. Learning outcome:  LO2:Be able to design Java solutions  LO3:Be able to implement Java solutions Assessment criteria: 
Association Class Generalization/Specialization Whole-Part Page More Associations 1.
Slide 1 Structural Modeling Chapter 7. Slide 2 Key Ideas A structural or conceptual model describes the structure of the data that supports the business.
Chapter 7 System models.
System models l Abstract descriptions of systems whose requirements are being analysed.
Modified by Juan M. Gomez Software Engineering, 6th edition. Chapter 7 Slide 1 Chapter 7 System Models.
Structural Modeling. Objectives O Understand the rules and style guidelines for creating CRC cards, class diagrams, and object diagrams. O Understand.
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.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
Fall 2010 CS4310 Requirements Engineering A Brief Review of UML & OO Dr. Guoqiang Hu Department of Computer Science UTEP 1.
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.
An Introduction to the Unified Modeling Language
Lecture 6: Structural Modeling
What is a Structural Model?
Lecture 1: UML Class Diagram September 12, UML Class Diagrams2 What is a Class Diagram? A class diagram describes the types of objects in the system.
UML as a Specification Language for Embedded Systems. By, Mir Ahmed Ali, Asst. Professor, ECM department, SNIST. By, Prof. Narsiah sir, Director of School.
Design Model Lecture p6 T120B pavasario sem.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
 Building Block Building Block  Things in the UML Things in the UML  Structural Things Structural Things  Behavioral Things Behavioral Things  Grouping.
Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey A.
Chapter 3: Introducing the UML
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
 To explain why the context of a system should be modelled as part of the RE process  To describe behavioural modelling, data modelling and object modelling.
Object-Oriented Software Engineering Practical Software Development using UML and Java Modelling with Classes.
CSCI 383 Object-Oriented Programming & Design Lecture 7 Martin van Bommel.
UML Diagrams: Class Diagrams The Static Analysis Model
Course Outcomes of Object Oriented Modeling Design (17630,C604)
Object-Oriented Analysis and Design
Unified Modeling Language
Analysis and Design with UML: Discovering Classes and Relationships
UML Class Diagrams: Basic Concepts
Analysis and Design with UML: Discovering Classes and Relationships
Copyright 2007 Oxford Consulting, Ltd
Analysis and Design with UML: Classes and Relationships
Chapter 22 Object-Oriented Systems Analysis and Design and UML
Object Oriented System Design Class Diagrams
Presentation transcript:

Object Oriented Modelling Class & Object Models

Analysis V. Design There is no significant distinction between the techniques used during Analysis and those used during Design. The techniques are equally valid during both stages. The principle difference is the level of objects you model with. The term “Object Modelling” is sometimes used instead of “Object Analysis” and Object Design”.

Analysis (logical model) Object-Oriented Analysis (OOA) aims to model the problem domain, the problem we want to solve by developing an OO system. Analysis level objects –Customers, accounts, suppliers, accidents, invoices –Protocols, motors, sensors, engines, traffic

Design (Physical Model) Object-Oriented Design (OOD) is an activity where we are looking for logical solutions to solve a problem. Design level objects –User interface (dialogue and presentation objects) –Objects to manage relationships, concurrency, –referential integrity, transactions, etc...

Unified Modelling Language (UML) UML is a non-proprietary specification language for object modeling. UML is a general-purpose modeling language that includes a standardized graphical notation used to create an abstract model of a system, referred to as a UML model. UML is not a method by itself; however, it was designed to be compatible with the leading object-oriented software development methods of its time. –Most well known method using UML is Rational Unified Process (RUP).

UML Model Types Static/Structural behaviour –Functional Model Showcases the functionality of the system from the user's Point of View. Includes Use case diagrams. –Object Model Showcases the structure and substructure of the system using objects, attributes, operations, and associations. Includes Class Diagrams. Dynamic Behaviour –Dynamic Model Showcases the internal behavior of the system. Includes Sequence Diagrams, Activity Diagrams and State Machine Diagrams. There are three prominent parts of a system's model covering two aspects of system behaviour:

UML Views Use-Case View: User perception of functionality in domain or system. Logical View: Internal representation showing both static structure and time- dependent dynamic behaviour. Component View: Showing how a complete system is composed of discrete units. Concurrency View: Division of system into separate execution threads - shows communication. Deployment View: Represents physical deployment of the various parts (components) of the overall system. Views provide high level representations of a domain or system. There are several:

UML Models Structure Diagrams emphasize what things must be in the system being modeled: –Class diagram –Component diagram –Composite structure diagram –Deployment diagram –Object diagram –Package diagram Behavior Diagrams emphasize what must happen in the system being modeled: –Activity diagram –State Machine diagram –Use case diagram Interaction Diagrams, a subset of behavior diagrams, emphasize the flow of control and data among the things in the system being modeled: –Collaboration / Communication diagram –Interaction overview diagram –Sequence diagram –UML Timing Diagram

Class Diagram A class diagram is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, and the relationships between the classes. (wikipedia)

Class Diagram A class is represented by a box –the name of the class in box. –a compartment below the class name can show the class's attributes (i.e. its properties). Data Behaviour (methods).

Classes and Objects Classname Class Name Data Attributes Methods/ functions/ behaviour OR Objectname: Classname Objectname: Classname Data Attributes Methods/ functions/ behaviour OR A class is a specification that an object implements

Identifying Classes A useful link:

Identifying Classes Natural language - Origins from Abbott 1983 CRC Cards - Beck Wirfs-Brock 1990

Natural Language Nouns may indicate candidate classes –Some nouns are actually sub-assemblies or aggregates of classes. –Some nouns suggest merely attributes of a class When sufficient significance can be assigned to an attribute it may be promoted to a full class. Verb phrases suggest class associations or operations –Often operations are tied to relationships Adjectives suggest attributes of a class Proper nouns suggest objects of a class type –Try not to have too many classes for which there is only ever one instance created. Original concept from Abbott 1983

Critique of Natural Language Analysis Needs a full and accurate statement of the requirements –Often the lack of clearly defined requirements is the reason why an OO approach may be being used. Nouns and Verbs tend only to help identify tangible things. –Much of design requires thinking about less tangible concepts - abstractions –Therefore natural language may contribute little to the design process. –Nevertheless, useful starting point for some analysis work. see Goldberg and Rubin 1995

Natural Language - Example A manager is responsible for a department and must review the staff in that department each year. The manager is also responsible for ordering new equipment (such as PCs) and furniture (such as desks and chairs) as required. From time to time John (one of the managers) must also recruit additional staff. This involves placing advertisements and keeping track of all applicants up to the closing date. A short-list of suitable candidates for interview is then composed.

Natural Language Example Examine the Model and think about what each of the Symbols mean

CRC Cards Brainstorming tool used to design OO software. Used when first determining required classes and how they interact. CRC cards are usually created from index cards on which are written: –The class name. –The responsibilities of the class. –The names of other classes that the class will collaborate with to fulfill its responsibilities.

CRC Cards Class Name: MANAGER Responsibilities Collaborators Beck & Cunningham 1989 Departmental reviews Staff salary reviews Ordering Equipment Staff recruitment Department Employee Applicant Class, Responsibility and Collaboration

CRC Cards l Write Class name on a 4” x 6” index card l Write Responsibilities on card uResponsibilities identify the problems which the class must solve. uGroup responsibilities into contracts. l Identify Collaborator classes on the card uCollaborator classes are classes which send messages to, or receive messages from, the class in question. uDIscard classes without collaborations. Beck & Cunningham 1989

Class Description l End up with a class description, either in textual prose or some more structured form. For example using a company Manager: Manager - A company employee and departmental controller. A manager is responsible for one or more employees. A manager can: Review staff salaries, order equipment and recruit staff. These activities may all be part of periodic departmental reviews.

Structured Description Class name: MANAGER Description: Details of a company MANAGER - a person Superclass: PERSON Name: Grade Description: Details of salary grading Type: Integer (range 1-5) Cardinality: One Name: Manages Description: Details of employees managed Type: Employee Cardinality: Many

Structured Description Public methods: Name: Review Department Parameters: New Budget Description: Used to carry out periodic reviews. Private methods: Name: Recruit Staff Parameters: Number of staff, type of staff Description: Initiated by a Manager as a consequence of various factors and as a result of a request to Review Department.

Object Relationships Most OOA&D methods (including UML) model 3 basic kinds of relationship: l Association l Aggregation (part_of) l Inheritance (is_a)

Object and Class Associations Links and Associations uLink - A physical or conceptual connection between two objects (instances) uAssociation - A group of links with a common structure. Associations occur between classes of objects. Links represent object interactions (dynamic considerations) while associations depict static, structural issues.

Links and Associations Lecturer Course takes An Association George: Lecturer takes M.Sc: Course A Link Class diagram Object diagram lecture examine

Participation or Cardinality While participation is shown on class diagrams it relates to the number of instances of one class that are associated with an instance of the other class. Class 1 Class 2 association name Class Exactly one Many (zero or more) Optional (zero or one) One or more Numerically specified 1..* * 1 role

Example 1 Lecturer Course Takes Joe Bloggs: Lecturer B.Sc: Course M.Sc: Course lecture examine 0..* 1..* Is taken by

Association Constraints You can document any constraints on the association. For example, a person may only drive a car if they have a valid licence: Person Car drives 0..* {person.licence_status = valid)

Handling Link Attributes via an Association Class A class may be attached to an association rather than directly to another class. Such a class is called an Association Class. It can have data attributes and behaviour just like any other class Used to hold information on each occurrence of a relationship Supplier Part Supplies Date Contract

Instances of the Association Class B&Q Texas Budget aHammer aSaw 21/12/92 14/2/93 27/4/91 12/5/93 5/9/93

Associations There can be more than one association between the same two classes –Person hires car –Person owns car –Person drives car Suggests 3 distinct relationships between a Person and a Car –May have different cardinalities Person hires many Cars A Car may be hired by many Persons (Over Time)

Example 2 Person Car hires owns 10..*

Time Dimension Time presents an interesting dimension when applied to associations. It often transforms a one:one into a one:many or a many:many. –For example, a Car can only be hired by one person at a time (Rule). But it may be hired by many people over a period of time. –The Rules must be identified by the analyst, so the designer can create the appropriate association participation.

Time Dimension If an Information System is required to track only details of who currently has a vehicle on hire, then the Car can be modelled in a One:One association with a Person. However, if the system must provide a historical log of all customers who hired a particular Car then a Many:Many association will be required.

Time Dimension A Person may Drive a Car for much shorter periods of time. Is a record of all driving periods required? –Perhaps for a haulage firm with a legal requirement to maintain a driving log for each Driver. –In another situation it may only be necessary to record information about who is currently driving a particular Car.

Aggregation Aggregation is the “part-whole” relationship. It relates classes, representing parts (or components) to the whole (or assembly) class.

Aggregation A tightly coupled form of association with some extra semantics, namely transitivity (if A is a part of B and B is a part of C then A is a part of C). Properties of the assembly may propagate to the components. For example, the speed and location of a door is obtained from a fuselage which in turn obtains them from a Plane. Rumbaugh 1991

UML Aggregation In UML there are three types of aggregation: –Normal Aggregation –Shared Aggregation –Composition aggregation

Aggregation l Aggregation is most useful when there are common properties of components that can be attached to the assembly as a whole l Or where operations can propagate from container to contained objects l Parts explosions are the most compelling examples of aggregation l Keywords to identify aggregates are: “consists of”, “contains”, or “is part of”. l Represented by as line with a hollow diamond attached to the ‘wholeside’ end of the line. l If in doubt, use ordinary association!

Aggregation Navy Warship Contains 0..*

Normal Aggregation - Discussion University Faculty School Lecturer works for Class diagram Course takes * * 11..*

Composition Aggregation The ‘whole’ owns the instances of the parts. Those instances cannot belong to any other instance of the whole. Composition Aggregation forms a tree structure. The lifetime of the whole dictates the lifetime of the constituent parts.

Composition Aggregation Example Aircraft EngineWing Fuselage Door Landing Gear

Alternative Notation Aircraft Engine Wing Fuselage 1+ 2 Door 2+ Landing Gear

Shared Aggregation in UML With ‘Shared Aggregation’ the parts can be associated with many wholes - for example several instances of a collection class may act as collectors for a given class. To use the example of staff recruitment, a candidate may be associated with an ‘applicants’ whole and at the same time be part of a ‘short-listed’ whole and eventually an ‘offer-made’ whole. Each of these wholes is acting as a collection class for ‘applicants’. List Applicant * * ‘Shared’ aggregation if mutiplicity > 1. Open diamond symbol for both sharded and ‘normal’ aggregation

Shared Aggregation in UML Lifetime of parts is not constrained by the lifetime of the container: –Parts can exist independently from the whole. –Much closer to the idea of a 1-many association. Shared aggregates form a network of parts rather than a tree structure.

Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable. In object-oriented analysis and design, an association represents a certain relationship between objects, but all objects have their own lifecycle and there is no ownership among the objects. For example, multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership among the objects and all have their own lifecycle.

Aggregation and composition both are specialized form of association. Composition is again specialize form of aggregation. An aggregation represents a whole that comprises various parts; so, a Committee is an aggregate of its Members. At implementation time, this relationship is not containment. (A meeting does not contain a room.) Similarly, the parts of the aggregate might be doing other things elsewhere in the program, so they might be referenced by several objects. In other words, There's no implementation-level difference between aggregation and a simple "uses" relationship (an "association" line with no diamonds on it at all). In both cases an object has references to other objects. Though there's no implementation difference, it's definitely worth capturing the relationship in the UML, both because it helps you understand the domain model better, and because there are subtle implementation issues. I might allow tighter coupling relationships in an aggregation than I would with a simple "uses," for example. Aggregation is the typical whole/part relationship. Same as an association with the exception that instances cannot have cyclic aggregation relationships (i.e. a part cannot contain its whole).

A whole cannot be its own part List A List cannot be part of its own list Person Child Parent

Composition [...] is exactly like Aggregation except that the lifetime of the 'part' is controlled by the 'whole'. Composition involves even tighter coupling than aggregation, and definitely involves containment. The basic requirement is that, if a class of objects (call it a "container") is composed of other objects (call them the "elements"), then the elements will come into existence and also be destroyed as a side effect of creating or destroying the container. It would be rare for an element not to be declared as private.

Aggregation should be used only in cases where there is a compositional relationship between classes, where one class is composed of other classes, where the "parts" are incomplete outside the context of the whole. Consider the case of an Order: it makes no sense to have an order which is "empty" and consists of "nothing". The same is true for all aggregates: Departments must have Employees, Families must have Family Members, and so on. If the classes can have independent identity outside the context provided by other classes, if they are not parts of some greater whole, then the association relationship should be used. In addition, when in doubt, an association is more appropriate; aggregations are generally obvious, and choosing aggregation is only done to help clarify. It is not something that is crucial to the success of the modeling effort.

Inheritance l Sometimes called the “is_a” relationship l Provides a way of sharing attributes and methods between subclasses (or child classes) and their superclasses (or parents) l Subclasses can share similarities with common superclasses while preserving their differences l Default types of attributes and logic of methods can be overridden in the subclasses

Inheritance – Abstract & Concrete classes An abstract class is designed to be a parent class that can not be instantiated. –Often represents abstract concepts or entities. –Usually has one or more abstract methods that only have a signature and no implementation. –Only used to inherit from.

Inheritance – Abstract & Concrete classes It is possible to instantiate a concrete class (i.e. possible to create object from). –must provide implementation for all methods.

Inheritance Example Build an inheritance hierarchy using the following items identified from OO Analysis. Student Qualifications Salary Lecturer Name Secretary Lecture

Inheritance sample solution Employee Student Qualifications Salary Lecturer Name Secretary Lecture LecturerSecretary Person Student Salary Name Lecture Where does Qualifications go?

Multiple Inheritance example Sales Person Manager Director Sales Manager

Class hierarchies Generalisation Specialisation

Class roles and Inheritance In a previous slide we looked at class roles: Lecturer Course takes Admin 1..* Here, the Person plays the role of a Course Tutor. Often such roles are modelled through inheritance: Lecturer Course Tutor

Using Class Hierarchies Generic class hierarchy copy Generic class Application specific class Using via sub-classing Instantiation of a generic class messages Using via delegation Instantiation of an application specific class

Don’t confuse Inheritance and Aggregation! Plane Engine Fuselage Wing * Not intuitive, therefore confusing to someone else. (A Plane is not a kind of Wing...)

Associations and Inheritance Plane CommercialPrivate Owns Crew Member Pilot Licence is_operated_by 1 1..*

Aggregation versus Inheritance l Aggregation is not the same thing as inheritance l Aggregation relates to Instances l Inheritance relates to Classes

Aggregation and Inheritance Plane Engine Fuselage Wing CommercialPrivate Military

Candidate Classes for a Library It is important to be aware of the relative stability of the various classes used in your object model. Not all classes will exhibit the same potential stability with respect to future required changes. l Component classes are likely to be more stable than container classes l Subclasses representing roles will be less stable than the more fundamental superclass

Fundamental Classes Scroll Bars Menus Cursors Lists Suitable material for inclusion in generic, re-usable class libraries

Composite Classes User interface window MenuIcon Window ScrollBarCursor..

Managing the bigger picture UML employs the notion of a Package as a mechanism for grouping related model elements. For example, groups of collaborating classes could be called a package. An overall system can then be composed from a number of packages. A UML Notation for a Package

UML Component Diagram An overall system may consist of a number of physical ‘components’ for example, where various classes are implemented in different code components. The notation is shown below: Component Name GUI User Room Booking

UML Deployment Diagram Different code components can be distributed amongst a number of processors or nodes in a network. The deployment diagram enables the designer to illustrate this distributed nature: Deployment diagram for a Room Booking System GUI: ClientA Booking: BuildingDiary User:UserBase >

Developing Static Models l Identify the main Use-cases and write down descriptions of these l Identify the main elements of information which must be stored. l Identify the main actors with which the system must interact. l Identify objects and classes l Identify associations between classes –Creating object model segments for each Use-case. l Identify attributes for classes l Merge the object model segments to create an overall object model for the system l Organise and simplify classes using inheritance l Test the object model and it’s relationships by performing walk- throughs using, for example, UML Sequence diagrams (Dynamic Modelling) l Iterate and refine the models

Class Model Summary The Class Model is used to identify classes and their inter-relationships. It provides a static, structural view of a system without any consideration of time sequencing or object interactions.