Class Modeling Design Class diagram. Classes The term “class ” refers to a group of objects that share a common attributes and common behaviour (operations).

Slides:



Advertisements
Similar presentations
UML (cont.) “The Unified Modeling Language User Guide” by G. Booch, J. Rumbaugh and I. Jacobson ● Classes ● Relationships ● Class diagrams ● Examples.
Advertisements

Object-oriented modeling Class/Object Diagrams
7M822 UML Class Diagrams 7 October 2010.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System modeling 2.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Classes and Object- Oriented Programming.
UML Class Diagram and Packages Written by Zvika Gutterman Adam Carmi.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Class Diagram & Object Diagram
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
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.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
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.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts.
OBJECT AND CLASES: THE BASIC CONCEPTS Pertemuan 8 Matakuliah: Konsep object-oriented Tahun: 2009.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
1 Chapter 2 (Cont.) The BA’s Perspective on Object Orientation.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
R McFadyen Chapter 7 Conceptual Data Modeling.
Systems Analysis and Design in a Changing World, 6th Edition 1 Chapter 4 - Domain Classes.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
CS3773 Software Engineering Lecture 04 UML Class Diagram.
Sommerville 2004,Mejia-Alvarez 2009Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
Unit 3 Conceptual Data Modeling. Key Concepts Conceptual data modeling process Classes and objects Attributes Identifiers, candidate keys, and primary.
Databases : Data Modeling 2007, Fall Pusan National University Ki-Joune Li.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
CS212: Object Oriented Analysis and Design Lecture 13: Relationship between Classes.
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.
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.
Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,
Class Diagram Classes are the most important building block of any object-oriented system. A class is a description of a set of objects that share the.
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.
Chapter 7,8,appendix C Object-Oriented Analysis and Design 20.1.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.
UML Part 1: Class Diagrams. Introduction UML stands for Unified Modeling Language. It represents a unification of the concepts and notations presented.
INFSY 535.  Small systems  Larger systems 1.Understand the program requirement- what 3. Write and test each part (unit testing) 4. Maintenance 2. Specify.
Classes, Interfaces and Packages
Object Modeling THETOPPERSWAY.COM. Object Modelling Technique(OMT)  Building a model of an application domain and then adding implementation.
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
1 SWE Introduction to Software Engineering Lecture 14 – System Modeling.
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.
Software Modelling Class Diagram. Class Diagrams The main building block in object oriented modeling They are used both for general conceptual modeling.
 Class and Diagram  Representation of Class Name Attributes Operations  Visibility of Attributes and Operations.
COMP 2710 Software Construction Class Diagrams
Visit for more Learning Resources
Class Diagrams.
Topics Procedural and Object-Oriented Programming Classes
Object-Oriented Modeling with UML
Class diagram Description
UML Class Diagrams: Basic Concepts
Object Oriented Analysis and Design
Software Engineering Lecture #11.
UML Class Diagram.
Unified Modelling Language
Understand and Use Object Oriented Methods
Information System Design
From Class Diagram to Contract Diagram
Presentation transcript:

Class Modeling Design Class diagram

Classes The term “class ” refers to a group of objects that share a common attributes and common behaviour (operations). Objects are instances of a class. A class is like a mold and an instance of a class is like a molded object. Example Mary is an object instance, while Student is an object class.

Classes All objects that exists within a class inherit its attributes and the operations that are available to manipulate the attributes. A super class is a collection of classes A subclass is a specialized instance of a class.

Classes A class has methods and attributes while object instances have behaviour and states Example: Bank account is a class which covers many different account types. John’s and Mary accounts are instances of the bank account class.

Bank Account -name -balance +debit(in amount) +credit(in amount) Object1 : Bank Account Name = John Smith Balance = 1, Object2 : Bank Account Name = Robert Jones Balance = -1,000.00

Classes The two instances are in different states. John’s account is in the credit state (positive balance), while Robert’s account is in the withdrawn state (negative balance). The state of the objects can be changed by calling the credit or debit operations. Robert’s account can be changed to the credit state if a credit operation is invoked with a parameter greater than 1000.

Attributes Things in the real world have properties. An attribute is a property of a class. Attributes attached to classes and objects describe the class or object. An attribute is a data item where an object holds its own state information. Attributes have a name, value and data type e.g. integer, Boolean.

Example : A class automobile has an attribute colour. The domain of values for colour is (white, black, silver, gray, blue, red, yellow, green). A book can be described in terms of its author, ISBN, publisher, etc.

Operations Each object can perform a set of functions in order to provide a number of services in a software system. A service is defined by one or more operations. An operation is a function or a procedure which can access the object’s data. An operation consists of two parts – name – argument(s) Thus each object must define its operation for each of its services. The collection of operations is the object’s interface. Other objects only need to know the interface of an object in order to invoke the operations provided by the object.

Operations An operation is sometimes called a method or a member function. Examples – withdraw(amount) – deposit (amount) – getbalance()

Encapsulation : Information Hiding It is only through such operations that other objects can access or manipulate the information stored in an object. The collection of operations provides an external interface to a class. The interface presents the outside view of the class without showing its internal structure or how the operations are implemented. It is only the producer, developer of that object that knows the details of the internal construction of that object. The users of an object are denied knowledge of the inner working of the object. Other objects only need to know the interface of an object in order to invoke the operations provided by the object. – Public interface – Protected interface Thus, objects are treated as black boxes. The implementation of objects are hidden from those that use them. This is a powerful concept called “Information Hiding”, better known as encapsulation principle.

Class diagram A class is depicted graphically in a class diagram. In UML, a class is represented by a rectangle with three compartments separated by horizontal lines. The class name appears in the top compartment, the list of attributes in the middle compartments and the list of operations in the bottom compartment of a box.

Shape -origin -color +move() +resize() BankAccount -account Name -customerName +getbalance(): float +setbalance() Examples

Naming Classes Classes are named as noun or a noun phrase. When using name phrases, eliminate the spaces and concatenate the words with their first letter in uppercase e.g. SavingAccount, BankAccount

Relationships Relationships exist among objects which links the type of link that exists between objects. Through the link it is possible to discover the other objects that are related to it. Association Generalization Aggregation

Association An association is a structural relationship that specifies that objects of one thing are connected to objects of another. A plain association is between two peer classes which means that both classes are conceptually at the same level, no one more important than the other. Given an association connecting two classes, one can navigate( send messages) from an object of one class to an object of the other class and vice versa. It is possible that an object of the class can be linked to other objects of the same class.

Association If an association connects between two objects instead of classes, it is called a link. A link is an instance of an association.

BillGates:Person Microsoft:Company Name of link WorkFor Links provide a convenient way to trace the relationship between objects. Specify only those relationships that are necessary for the system

Person Company Name of association WorkFor

Association There are four adornments that apply to associations. – Name – Role – Multiplicity – Note

Reflexive Association and Roles A reflexive association is an association that relates one object of a class to another object of the same class. In other words, a class can be associated with itself

Aggregation : Aggregation is a stronger form of association. To model a “whole/part or part-of relationship in which one class represents a larger thing ( the “whole”), which consists of smaller things (“ the parts”) is called aggregation. It represents a “has- a” relationship, meaning that an object of the whole has objects of the part. In UML, a link is placed between the whole and parts classes with a diamond head, attached to the whole class to indicate that this is an aggregation.

Company Department whole part aggregation 1 *****p Aggregation : * Part

Aggregation : Multiplicity can be specified at the end of the association for each of the part-of classes to indicate the quantity of the constituent parts. Aggregations are not named Keywords used to identify aggregations are “consists of”, contains, is part of.

A stronger form of aggregation is called composition, which implies whole class has exclusive ownership of the parts classes. This means parts may be created after a composite (whole) is created, but such parts will be explicitly removed before the destruction of the composite. In UML, a filled diamond indicates the composition relationship. Composition

Person Company EmployeeEmployer 1..n1 Example WorkFor Position -title -starting date -salary Division Department 1..n

School Instructor Course Department Student has attends Assigned to teaches 0…1 1..* ** * 1 1

Comparison AssociationAggregationComposition Is a relationship where all object have their own lifecycle Is a specialize form of Association where all object have their own lifecycle It is a strong type of Aggregation. Child object dose not have their lifecycle. There is no ownerThere is ownership and child object can not belongs to another parent object Sole ownership, parent object deletes all child object will also be deleted Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy Multiple choice questions: Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically delete

Inheritance The attributes and operations common to a group of subclasses are attached to a super- class and inherited by its sub-classes. Each subclass may also include new features on its own.

Properties of inheritance Generalization – The purpose of this property is to distribute the commonalities from the superclass among a group of similar sub classes. The subclass ( derived class) inherits all the super class's ( base class) operation and attributes.

Bank Account -account number -password -balance +getBalance() : float +setBalance() CheckingAccount +checkClearing() SavingsAccount -interest +addinterestToBalance()

Generalization BankAccount (superclass) has an attribute account_number and an operation getBalance(), the CheckingAccount (subclass) will also have the same attribute, account_number and the operation getBalance() as it is a subclass of BankAccount. It is unnecessary and inappropriate to show the superclass attributes and operations in the subclasses

Specialization Specialization allows subclasses to extend the functionalities of superclass. A subclass can introduce new operations and attributes of its own. Example SavingsAccount inherits attributes account_number, password and balance from BankAccount and extends the functionalities of BankAccount with an additional attribute, interest and an additional operation, addInterestToBalance. A SavingsAccount has the attribute interest that BankAccount does not because not all bank accounts earn interest.

Example - specialization A subclass Y inherits all of the attributes and operations associate with its super-class X. This means that all data structures and algorithms originally designed and implemented for X are immediately available for Y- no further work need be done. Reuse has been accomplished directly. Any change to the data or operations contained within a super-class is immediately inherited by all subclasses that have inherited from the super- class. Therefore a change in the super class is immediately propagated through a system.

Inheritance Also, at each level of the class hierarchy, new attributes and operations may be added to those classes that have been inherited from higher levels in the hierarchy.

X1 CHAR1 CHAR2 CHAR3 X1 X2 CHAR1 CHAR2 CHAR3 CHAR4 CHAR5 X3 CHAR1 CHAR2 CHAR3 CHAR4 CHAR5 CHAR6 X4 CHAR1 CHAR2 CHAR3 CHAR4 CHAR5 CHAR7 CHAR 4 + CHAR 5 CHAR 7 CHAR 6

Library class hierarchy

User class hierarchy

Multiple inheritance Rather than inheriting the attributes and services from a single parent class, a system which supports multiple inheritance allows object classes to inherit from several super- classes Can lead to semantic conflicts where attributes/services with the same name in different super-classes have different semantics Makes class hierarchy reorganisation more complex

Multiple inheritance

Abstract Classes An abstract class is used to specify the required behaviour ( operations) of a class providing their actual implementation. An operation without the implementation (body) is called an abstract operation. A class with one or more abstract operations is an abstract class. An abstract class can act as a repository of shared operation signatures for its subclasses and so those methods must be implemented by subclasses according to the signatures.

Shape -origin -color +move() +resize() +draw() Rectangle +draw() Circle +draw() Polygon +draw()