0% found this document useful (0 votes)
20 views29 pages

Classes &relnships

Uploaded by

vsteph223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views29 pages

Classes &relnships

Uploaded by

vsteph223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

9/16/24

DA-IICT

IT313: Software Engineering

Classes and their relationships

Saurabh Tiwari

OO Concepts

1
9/16/24

Polymorphism

Super class vs. Sub class

?
tion?
aliza
ener
t is G
Wha

Specialization: The act of defining one class as a refinement of another.

Subclass: A class defined in terms of a specialization of a superclass using


inheritance.

Superclass: A class serving as a base for inheritance in a class hierarchy

Inheritance: Automatic duplication of superclass attribute and behavior


definitions in subclass.

2
9/16/24

Class Modeling

Objects

The most fundamental entity in an OO Program

“An Object is a concept, abstraction or thing with identity that has


meaning for an application”
• Defined by class data type

Consists of
• Identifier
• Values
• Behavior

3
9/16/24

Software Object: Cycle

Classes

• A class is a pattern, a blue print, or a template for a category of


structurally identical entities
• Created entities are called objects or instances
– Class is like instance factory
– Static entity
• A class has three components
– Name
– Attributes (also termed as variables, fields, or properties)
– Methods (also termed as operations, features, behavior,
functions)

4
9/16/24

Classes
Objects

Class

Classes are represented by rectangles, with the name of the


class, and can also show the attributes and operations of the
class in two other “compartments” inside the rectangle.

10

5
9/16/24

Class Diagrams

A Class defines the attributes and the methods of a set of objects.

All objects of this class (instances of this class) share the same
behaviour, and have the same set of attributes (each object has its
own set).

Class diagrams provide a graphic notation for modeling classes and


their relationships thereby describing possible objects.

2013: J Paul Gibson

Class Diagrams

6
9/16/24

Class Diagrams

Attributes
In UML, Attributes are shown with at
least their name, and can also show
their type, initial value and other
properties. Attributes can also be
displayed with their visibility:
+ public attributes

# protected attributes

- private attributes

2013: J Paul Gibson

Class Diagrams

Operations

Operations (methods) are also


displayed with at least their name,
and can also show their parameters
and return types. Operations can,
just as Attributes, display their
visibility:

+ public operations

# protected operations

- private operations

2013: J Paul Gibson

7
9/16/24

Class and Objects

15

Class and Objects: Notations

Do not list object identifier; they are implicit in models

16

8
9/16/24

Object Relationships

• Association
• Aggregation
• Composition

• Inheritance
• Dependency

17

Link & Association

• Link is a physical or conceptual connection among objects


• Association is a description of a group of links with common
structure and common semantics

anAssociation aLink
A B anA:A aB:B
* *

anAssociation aLink
A *anotherAssociation* B anA:A aB:B
* * anotherLink

Class Diagram Object Diagram

18

9
9/16/24

Association

19

Multiplicity

Multiplicity specifies “the number of instances of one class that


may relate to a single instance of an associated class”.

• “One” or “Many”
• Infinite (subset of the nonnegative integers)

UML Specifies multiplicity with an interval


• “1” (exactly one)
• “1…*” (one or more)
• “3..5” (three to five, inclusive)
• “*” (zero or more)

20

10
9/16/24

Association

Visual representation

One-to-one association

Each country has one capital city


Textual representation

21

Association

Many-to-one association

Person Company
OwnStock
name name
* *

Many-to-many association

22

11
9/16/24

Association End Names

Interpretation?
Person and Company participate in association “WorkFor”

A Person is an employee with respect to a company


A Company is an employer with respect to a Person

23

Association End Names

A Workstation may have one of its window designated as the


console to receive general error messages.
Interpretation??

Workstation Window

name type
1 1

Is it possible that no console window exists?

Workstation Window
console
name type
1 0..1

24

12
9/16/24

Association End Names

Association End Names are necessary for associations between


two objects of a same class

25

Question?

How to model parent-child relationship?

Parent Child

name name
2 *

Person

name Parent

0..2

Child *

26

13
9/16/24

Association: Ordered, Sequence, Bag

• Ordered means that the objects are ordered in the collection of associated
elements.
• Sequence means that the association implements an ordered bag, that is an
ordered collection of elements where the same elements may occur several times

27

Question?

Man Women

name myhusband mywives


name
1..* 1..*

{……}

Ordered
Sequence

28

14
9/16/24

Association Class

UML offers the ability to describe links of association with


attributes like any class.

An association class is an association that is also a class.

Salary ?
Job Title ?

29

Association Class

Salary ?
Job Title ?

30

15
9/16/24

Association Class

31

Association Class

32

16
9/16/24

Association Class vs Ordinary Class

Association Class

Ordinary Class

33

Question?

Users may be authorized on many workstations. Each


authorization carries a priority and access privileges. A user
has a home directory for each authorized workstation, but
several workstations and users can share the same home
directory.

34

17
9/16/24

Qualified Association

• A qualified association is an association in which an attribute


called Qualifier disambiguates the objects for a ‘many’
association end.

• A qualifier selects among the target objects, reducing the


effective multiplicity for ‘many’ to ‘one’.

• Both below models are acceptable but the qualified model adds
information.

35

Qualified Association

36

18
9/16/24

N-ary Association

Programmer

Class Diagram

37

N-ary Association

Instance Diagram

38

19
9/16/24

N-ary Association Class

39

N-ary Association Class

40

20
9/16/24

Summary

• Objects may have relationships (among the same type or


different types)

• Loosely coupled (relatively independent) objects are related


with Association

• Association is shown by (optional) association name and


association end names

• Multiplicity represents the cardinality of the relationship


stating one object of a class is associated with how many
number of objects of the other class

41

Next Lecture…
Object Relationships: Association (Aggregation,
Composition) & Inheritance, Dependency

21
9/16/24

Generalization/Inheritance

• Generalization is the relationship between a class (superclass) and


one or more variations of the class (subclasses).

• Generalization organizes classes by their similarities and their


differences, structuring the descriptions of objects.

• A superclass holds common attributes, attributes and associations.

• The subclasses adds specific attributes, operations, and associations.


They inherit the features of their superclass.

• Often Generalization is called a “IS A” relationship

• Simple generalization organizes classes into a hierarchy.

• A subclass may override a superclass feature (attribute default


values, operation) by redefining a feature with the same name.

• Never override the signature of methods.

22
9/16/24

Use of generalization

• Used for three purposes:


– Support of polymorphism:
• polymorphism increases the flexibility of software.
• Adding a new subclass and automatically inheriting superclass
behavior.
– Structuring the description of objects:
• Forming a taxonomy (classification), organizing objects according
to their similarities. It is much more profound than modeling
each class individually and in isolation of other similar classes.

– Enabling code reuse:


• Reuse is more productive than repeatedly writing code from
scratch.

Aggregation

• Aggregation is a strong form of association in which


an aggregate object is made of constituent parts.
• The aggregate is semantically an extended object that
is treated as a UNIT in many operations, although
physically it is made of several lesser objects.

• Aggregation is a transitive relation:


– if A is a part od B and B is a part of C then A is also a part of C
• Aggregation is an antisymmetric relation:
– If A is a part of B then B is not a part of A.

23
9/16/24

Aggregation versus Association

• Aggregation is a special form of association, not an independent


concept.
• Aggregation adds semantic connotations:
– If two objects are tightly bound by a part-whole relation it is an
aggregation.
– If the two objects are usually considered as independent, even
though they may often be linked, it is an association.ِ
• Discovering aggregation
– Would you use the phrase part of ?
– Do some operations on the whole automatically apply to its parts?
– Do some attributes values propagates from the whole to all or some
parts?
– Is there an asymmetry to the association, where one class is
subordinate to the other?

24
9/16/24

Aggregation versus Composition

• Composition is a form of aggregation with additional


constraints:

– A constituent part can belong to at most one assembly


(whole).
• it has a coincident lifetime with the assembly.
• Deletion of an assembly object triggers automatically a deletion
of all constituent objects via composition.

– Composition implies ownership of the parts by the whole.


• Parts cannot be shared by different wholes.

25
9/16/24

Propagation of operations

• Propagation is the automatic application of an operation to a


network of objects when the operation is applied to some
starting object.

• Propagation of operations to parts is often a good indicator of


propagation.

Exercises

26
9/16/24

Example 1: University Courses

• Some instructors are professors, while others have job title


adjunct

• Departments offer many courses, but a course may be offered


by >1 department

• Courses are taught by instructors, who may teach up to three


courses

• Instructors are assigned to one (or more) departments

• One instructor also serves a department chair

Class Diagram for Univ. Courses

chairs
0..1

Department 1
assigned to 1..*
1..*

1..*
Instructor

1
offers
teaches
1..* 0..3

Course Adjunct Professor

27
9/16/24

Example 2: Problem Report Tool

• A CASE tool for storing and tracking problem reports

– Each report contains a problem description and a status

– Each problem can be assigned to someone

– Problem reports are made on one of the “artifacts” of a


project

– Employees are assigned to one or more project

– A manager may add new artifacts and assign problem


reports to team members

Class Diagram for Prob. Rep. Tool

10..*
Assigned To Artifact
Employee 1..* Project 1

0..* +name : string


+name : string +name : string
+status : enum
1
1
Responsible For
0..n About

Manager Developer Problem Report 0..n

1
1 0..*
Managed By History Log
0..n

History Entry
Code Bug Report

-when : Date
-whatDone : string

28
9/16/24

Questions??

29

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy