lecture 4 class diagram
TRANSCRIPT
Duration : 3 hrs
1
Ramakant SoniAssistant Professor
Dept. of Computer Science
B K Birla Institute of Engineering & Technology, Pilani, India
Ramakant Soni @ BKBIET PIlani
Class Diagram Overview
Class diagram is one type of UML structure diagramwhich shows structure of the designed system at thelevel of classes and interfaces, shows their features,constraints and their relationships - associations,generalizations, dependencies, etc.
Ramakant Soni @ BKBIET PIlani 2
ClassName
attributes
A class is a description of a set of objectsthat share the same attributes, operations,relationships, and semantics.
Graphically, a class is rendered as arectangle, usually including its name,attributes, and operations in separate,
operationsattributes, and operations in separate,designated compartments.
Ramakant Soni @ BKBIET PIlani
ClassName
attributes
The name of the class is the only required tag in the graphical representation of a class. It always appears in the top-most compartment.
operations
Ramakant Soni @ BKBIET PIlani
Person
name : Stringaddress : Addressbirthdate : Date
An attribute is a named property of a classthat describes the object being modeled.
In the class diagram, attributes appear in thebirthdate : Datessn : Id
In the class diagram, attributes appear in thesecond compartment just below the name-compartment.
Ramakant Soni @ BKBIET PIlani
Person
name : Stringaddress : Address
Attributes are usually listed in the form:
attributeName : Type
A derived attribute is one that can becomputed from other attributes, but doesn’tactually exist.
address : Addressbirthdate : Date/ age : Datessn : Id
For example, a Person’s age can becomputed from his birth date. A derivedattribute is designated by a preceding ‘/’ asin:
/ age : Date
Ramakant Soni @ BKBIET PIlani
Person
+ name : String# address : Address
Attributes can be:+ public# protected- private
# address : Address# birthdate : Date/ age : Date- ssn : Id
- private/ derived
Ramakant Soni @ BKBIET PIlani
Person
name : Stringaddress : Addressbirthdate : Datebirthdate : Datessn : Id
Eat()Sleep()Work()Play()
Operations describe the class behavior and appear in the third compartment.
Ramakant Soni @ BKBIET PIlani
A class may also include its responsibilities in a class diagram.
A responsibility is a contract or obligation of a class to perform a particular service.
SmokeAlarm
Responsibilities
-- sound alert and notify guard stationwhen smoke is detected.
-- indicate battery state
Ramakant Soni @ BKBIET PIlani
In UML, object interconnections (logical or physical), are modeled as relationships.
There are five kinds of relationships in UML:
• dependencies
• generalizations
• associations
•Inheritence
•realization
Ramakant Soni @ BKBIET PIlani
A dependency indicates a semantic relationship between two ormore elements. The dependency from CourseSchedule to Courseexists because Course is used in both the add and remove operations of CourseSchedule.
CourseSchedule
add(c : Course)remove(c : Course)
Course
Ramakant Soni @ BKBIET PIlani
PersonA generalization connects a subclass to itssuper class.
It denotes an inheritance of attributes andbehavior from the super class to thebehavior from the super class to thesubclass and indicates a specialization inthe subclass of the more general superclass.
Student
Ramakant Soni @ BKBIET PIlani
Student
UML permits a class to inherit from multiple superclasses, although some programming languages (e.g., Java) do not permit multiple inheritance.
Employee
TeachingAssistant
Ramakant Soni @ BKBIET PIlani