Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.

Slides:



Advertisements
Similar presentations
Object-Oriented Software Engineering Visual OO Analysis and Design
Advertisements

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
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.
1 CIS224 Software Projects: Software Engineering and Research Methods Lecture 4 Class Models (Based on Fowler (2004, Chapters 3 & 5) and Stevens and Pooley.
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System modeling 2.
Unified Modeling Language
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Software Engineering COMP 201
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Essentials of class models. 2 A very simple class model In UML, a class is shown in a class diagram as a rectangle giving its name.
Slide 1 Systems Analysis & Design CS183 Spring Semester 2008 Dr. Jonathan Y. Clark Course Website:
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
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.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Class Diagram & Object Diagram
Copyright 2004 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Second Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 Class and Object Diagrams PRACTICAL OBJECT-ORIENTED DESIGN WITH.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation (Adapted) Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra,
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
Objects What are Objects Observations
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
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.
System models Abstract descriptions of systems whose requirements are being analysed Abstract descriptions of systems whose requirements are being analysed.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright 2001 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix A Object-Oriented.
High-Level Design With Sequence Diagrams COMP314 (based on original slides by Mark Hall)
Detailed design – class design Domain Modeling SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
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.
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.
CS3773 Software Engineering Lecture 04 UML Class Diagram.
Sommerville 2004,Mejia-Alvarez 2009Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
1 Class Diagrams: The Essentials. 2 Terms and Concepts A class is... The most important building block of any object-oriented system. A description of.
1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.
© 2005 Prentice Hall9-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 Chapter 7 System Models.
Modeling system requirements. Purpose of Models Models help an analyst clarify and refine a design. Models help simplify the complexity of information.
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
Structural Modeling Chapter 7. Key Ideas A structural or conceptual model describes the structure of the data that supports the business processes in.
Week III  Recap from Last Week Review Classes Review Domain Model for EU-Bid & EU-Lease Aggregation Example (Reservation) Attribute Properties.
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.
12 OBJECT-ORIENTED DESIGN CHAPTER
INFO 620Lecture #71 Information Systems Analysis and Design Design Class Diagrams and others INFO 620 Glenn Booker.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
Object Oriented Programming and Data Abstraction Earl Huff Rowan University.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
Data Modeling Using the Entity- Relationship (ER) Model
Structural Modeling.
Course Outcomes of Object Oriented Modeling Design (17630,C604)
Object-Oriented Analysis and Design
OO Domain Modeling With UML Class Diagrams and CRC Cards
Object-Oriented Analysis
Object Oriented Analysis and Design
Chapter 22 Object-Oriented Systems Analysis and Design and UML
Object Oriented System Design Class Diagrams
Presentation transcript:

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture 19 – Essentials of Class Models 1COMP201 - Software Engineering

On Naming classes NO PLURALS! Personnot Persons Carnot Cars NO VERBS Encrypt X Not general process descriptors Encryption X Encryptor or EncryptionHelper Printer Good, Printing Bad COMP201 - Software Engineering2

Class Models In this lecture we will be studying Class Models which are a part of the Unified Modeling Language (UML). Of the various models in UML, we have the categories: Use case models – describing a system from the users’ point of view; Static models – describing the elements of the system and their relationship; class models fall into this category; Dynamic models – describing the behaviour of the system over time. COMP201 - Software Engineering3

A Very Simple Class Model In the Unified Modelling Language (UML), a class is shown in a class diagram as a rectangle giving its name: 4COMP201 - Software Engineering

What Makes a Good Class Model? Ultimately, we have two objectives which we aim to meet: 1. Build, as quickly and cheaply as possible, a system which satisfies our current requirements; Every piece of behaviour required of the system must be provided by the objects we choose 2. Build a system which will be easy to maintain and adapt to future requirements (Evolution) Thus build a system composed of encapsulated modules with low coupling and high cohesion. 5COMP201 - Software Engineering

In Order to Meet the Objectives: A good class model consists of classes which represent enduring classes domain objects, which don’t depend on the particular functionality required today Remember that the names of classes are also important; use meaningful names for classes when possible and consider using a data dictionary to avoid conflicts 6COMP201 - Software Engineering

Deriving Classes Recall that we previously mentioned the noun identification technique to find potential classes. There are two main (extreme) techniques used to find classes in general: Data-driven-design (DDD) – We identify all the data of the system and divide it into classes. We then assign particular responsibilities (methods) to these classes Responsibility-driven-design (RDD) – We identify all the responsibilities of the system and divide them into classes. We then find the data each class requires. COMP201 - Software Engineering7

Associations In the same sense that classes correspond to nouns, associations correspond to verbs. They express the relationship between classes. There are instances of associations, just as there are instances of classes Instances of a classes are called objects; Instances of associations are called links in UML 8COMP201 - Software Engineering

Class A and B are Associated if an object of class A sends a message to an object of class B an object of class A creates an object of class B an object of class A has an attribute whose values are objects of class B or collections of objects of class B an object of class A receives a message with an object of class B as argument 9 In other words, if some object of class A has to know about some object of class B COMP201 - Software Engineering

Simple Association between Classes One annotation which is often used early is the multiplicity of an association This is so fundamental that we will spend some time thinking about it. 10COMP201 - Software Engineering

Example Doctor is associated by has allocated with just one or more than one patient. We showed a 1 at the Doctor end of the association (alternately we can use 1..1) On the other hand, there may be any number of patients for a given Doctor in our system. So the multiplicity on the Patient end is 1..*. 11COMP201 - Software Engineering

Multiplicity We can specify: an exact number simply by writing it, e.g. 1 a range of numbers using two dots between a pair of numbers, e.g., an arbitrary, unspecified number using * Loosely, you can think of UML’s * as an infinity sign, so the multiplicity 1.. * expresses that number of copies can be anything between 1 and infinity. 12COMP201 - Software Engineering

Attributes and Operations The attributes of a class describe the data contained in an object of the class and their type Most important are the operations of a class, which define the ways in which objects may interact. 13COMP201 - Software Engineering

Operation Signatures The signature of an operation gives the selector, names and types of all formal parameters (arguments) and the return type. For example: computeMean(List inputList): Float Recall that the method called may depend upon a classes position within the inheritance hierarchy. There may be methods with the same name, do you remember the concept of dynamic binding? 14COMP201 - Software Engineering selector Argument type Argument name Return type

Dynamic Binding (recap) Vehicle v = null; v = new Car(); v.startEngine(); v = new Boat(); v.startEngine(); 15COMP201 - Software Engineering Call Car startEngine() method Call Boat startEngine() method

Generalization Important relationships which may exist between classes are called generalization. Conceptually this means that if class A is a generalization of class B, then the interface of class B must conform to the interface of class A. Every attribute and operation of A will also be supported by B. In addition, B may contain some extra operations and data specific to its class. Let’s see an example of this on the next slide… 16COMP201 - Software Engineering

Generalization An object of a specialized class can be substituted for an object of a more general class in any context which expects a member of the more general class, but not the other way round 17COMP201 - Software Engineering Animal Age: Integer getAge(): Integer Cat meow(): void Dog bark(): void

Generalization 18COMP201 - Software Engineering Animal Age: Integer getAge(): Integer Cat meow(): void Dog bark(): void Animal any = new Animal(12); any.getAge(); any.meow(); any.bark(); Fine, returns 12 Error – No meow() method! Error – No bark() method!

Animal any = new Cat(8); any.getAge(); any.meow(); any.bark(); Generalization 19COMP201 - Software Engineering Animal Age: Integer getAge(): Integer Cat meow(): void Dog bark(): void Fine, returns 8 Fine, object “meows” Error – No bark() method!

Inheritance versus Generalization Generalization is a conceptual relationship between classes whereas inheritance is an implementation relationship. Generalization obviously increases the coupling of a system and if a subclass is changed it usually necessitates a recompilation of the subclass also (this is a pragmatic issue). COMP201 - Software Engineering20

CRC Cards One common way of checking for a good design and guiding its refinement is to use CRC cards. CRC stands for Classes, Responsibilities, Collaborations. Although CRC is not part of UML, they add some very useful insights throughout a development. 21COMP201 - Software Engineering

Creating CRC Cards The name of a class, at the top The responsibilities of the class, on the left-hand side The collaborators of the class, which help to carry out each responsibility, on the right-hand side of the card. The responsibilities of the class describe at a high level the purpose of the class’s existence : They are connected with the operations the class provides, but are more general than that might imply – i.e., they can be an abstraction of several operations. 22COMP201 - Software Engineering

CRC Cards In general there should be one or two responsibilities per class and usually no more than four. Too many responsibilities often signals low cohesion (i.e., a bad level of abstraction) in the system. Too many collaborators can signify high coupling in the system (the class is connected to too many other classes). Since we aim to have systems with high cohesion and low coupling, we should aim to find a compromise between these values which is still conceptually sound. 23COMP201 - Software Engineering

CRC Card Example 24COMP201 - Software Engineering Questions: Do these three classes conform to our notion of a good design? What is their level or cohesion and coupling?

CRC Card of a Bad Object Class 25COMP201 - Software Engineering Questions: Why is this a bad class according to the principals of good design we have identified? How can it be improved? Word_Processor_Object ResponsibilitiesCollaborators 1. Spellcheck the document 2. Print the document 3. Open a new document 4. Save the document 5. document Dictionary Printer File I/O Networking API Here is an example of a CRC card for a bad object class called Word_Processor_Object:

More about Associations One of UML’s strengths is its expressiveness, and during this lecture we have seen a taste of that, covering most (but not quite all) features of class diagrams. 26COMP201 - Software Engineering

More on Class Models Aggregation and composition Roles Navigability Qualified association Derived association Constraints Association classes More about classes We study these next lecture … 27COMP201 - Software Engineering

Lecture Key Points During this lecture we introduced class diagrams which represent the static (as opposed to the dynamic) nature of the system to be built. We discussed how classes and their associations can be found and the concept of multiplicity. We also discussed class attributes and operations as well as looking at representations of generalization. Finally we used the idea of CRC cards to validate a model. COMP201 - Software Engineering28