0% found this document useful (0 votes)
204 views37 pages

Lecture 8-Domain Model and Class Diagrams

This document discusses domain models and class diagrams. It defines a domain model as a visual representation of conceptual classes or real-world objects without any operations or methods. A domain model shows conceptual classes, associations between classes, and attributes of classes, but does not include software components or responsibilities. It also discusses criteria for useful associations in domain models and how to identify conceptual classes. The document then discusses class diagrams, which show the static structure of a system by defining model elements like classes, interfaces, relationships, attributes, and operations.

Uploaded by

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

Lecture 8-Domain Model and Class Diagrams

This document discusses domain models and class diagrams. It defines a domain model as a visual representation of conceptual classes or real-world objects without any operations or methods. A domain model shows conceptual classes, associations between classes, and attributes of classes, but does not include software components or responsibilities. It also discusses criteria for useful associations in domain models and how to identify conceptual classes. The document then discusses class diagrams, which show the static structure of a system by defining model elements like classes, interfaces, relationships, attributes, and operations.

Uploaded by

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

Lecture 8

Domain Model
Class Diagram

INSTRUCTOR: MS. Sundas Shujah

DEPARTMENT OF COMPUTER
SCIENCE

FALL 2019
What is a Domain Model?
 A domain model is a visual representation of conceptual
classes or real-world objects in a domain of interest.
 In UML, a domain model is illustrated with a set of class
diagrams in which no operations/methods are defined.
 Also known as Visual Dictionary
 It shows:
conceptual classes (concepts / domain objects)
associations between conceptual classes
attributes of conceptual classes
DOMAIN MODELS DO NOT SHOW
SOFTWARE COMPONENTS

– A domain model is a visualization of things in the real-world domain of


interest, not of software classes.
– The following elements are not suitable in a domain model:
– software artifacts
– Windows, databases, etc.
– Unless domain is software POSApplet
– responsibilities or methods
– They are part of design and software

Sale
date
print()
A Domain Model is Conceptual class,
not a Software Artifact

Conceptual Class:
Software Artifacts:

Sale SalesDatabase

amt
vs. Sale
item
Double amt;
Item item;
What’s the void print()
difference?
CRITERIA FOR USEFUL
ASSOCIATIONS

– The name of an association should be a verb or a verb


phrase.
– readable and meaningful in the model context.
– We need to be selective when adding associations to a
domain model.
– There can be n*(n-1) possible associations in a domain model
with n different conceptual classes.
– Too many associations in a domain model can make it difficult
to understand which defeats its purpose as a communication
tool.
MULTIPLICITY

– Multiplicity defines how many instances of a class A


can be associated with one instance of a class B.

Stocks
Store Item
1 *

association multiplicity
MULTIPLICITY
ATTRIBUTE

 Classes also include attributes relevant to the domain


 Attributed should have simple types (numbers, text,
booleans, etc.)
 An attribute is a logical data value of an object.
 Attributes can be “derived”, meaning that they can
be inferred, by means of a formula, from other
attributes or association.
For example, a receipt normally includes the date and time of
sale.
NOTATION FOR ATTRIBUTES

attributes

– The type of an attribute is optional.


ATTRIBUTES AS FOREIGN KEYS

– Do not use attributes as foreign keys to relate conceptual


classes (as typically done in relational database designs).

– Use associations to relate those classes.


Drawing the Domain model
Identify conceptual classes
from noun phrases
– Noun phrases may also be attributes or parameters rather than classes:
– If it stores state information or it has multiple behaviors, then it’s a class
– If it’s just a number or a string, then it’s probably
an attribute
Class Diagram Perspectives
– Conceptual Perspective
– Domain Model
– Software/Design Perspective
– Class Diagram
Class Diagrams
• A Class diagram shows the static structure of the system.

– It shows how a system is structured rather than how it behaves.

• It defines model elements such as classes, interfaces, and user-defined data types,
their internal structure, and their relationships to each other.

• Relationships, or associations, are shown as lines connecting elements, and are


annotated to describe the relationships and their cardinality (1..1, 1..*, 0..*, etc.).

• Inheritance (generalize/specialize), aggregation (comprises), and composition (has)


relationships are also captured in this diagram.

• Class attributes and their data types are identified here, as are the operations and
their return types.
Class Diagrams
• Class diagrams show the relationships among and details about each
class.

• Class diagrams are also the foundation for component and deployment
diagrams.

• Visibility allows to constrain the usage of a named element, is


indicated by +, #, -.
 Public visibility is represented by '+' literal.

 Private visibility is represented by '-' literal.

 Protected visibility is represented by '#' literal.


Attributes and operations
– Most important are the operations of a class, which define the ways in
which objects may interact.
– The attributes of a class describe the data contained in an object of the
class
UML Class properties

 Note Symbols
 Association
 Multiplicity
 Generalization
 Aggregation and composition
 Navigability
 Constraints
 Interfaces
Note Symbols

May represent several one of the following:


– UML note or comment, which by definition have no semantic impact
– UML constraint, in which case it must be encased in braces '{…}’
– A method body the implementation of a UML operation
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
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

in short, if some object of class A has to know about some


object of class B
Example

1..* 1

 Every copy is associated by is a copy of with just one book.


We showed a 1 at the Book end of the association.

 On the other hand, there may be any number of copies of a


given book in our system. So the multiplicity on the Copy
end is 1..* .
Multiplicity

We can specify:

 an exact number simply by writing it

 a range of numbers using two dots between a pair of


numbers

 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.
Multiplicity
 Association with two objects could be for more than one class
the measure of this is called multiplicity. It describe in range as
below:

 Lower Bound….Bound

 0..1 Single Value

 0.. * single value lower bound and upper bound unlimited


denoted by *.

 1..3 Lowest 1 Highest 3

 7..10.13 Lowest 7 Highest Min 10 Max 13


Generalization
– Important relationship which may exist between classes is
generalization. A generalization is used to indicate
inheritance.
Example

– The following diagram


shows a parent class
generalizing a child class.
Implicitly, an instantiated
object of the Circle class
will have attributes
x_position, y_position and
radius and a method
display(). Note that the class
"Shape" is abstract, shown
by the name being italicized.
Aggregation and composition

 Aggregation and composition are kinds of association:


 Instead of just showing that two classes are associated we may
choose to show more about what kind of association this is

 Aggregation and composition are both ways of recording


that an object of one class

is part of

an object of another class.


Aggregation

– The notation with open


diamond, denotes
aggregation, which is
more general way of
denoting a part-whole
relationship in UML
28

Composition
– Composition is a stronger form of aggregation - a composite
aggregation - is shown by a black diamond-shaped arrowhead
– In composition association, the whole strongly owns its parts
– If the whole object is copied or deleted, its parts are copied or deleted
with it
– The multiplicity at the whole end of a composition association must be
1 or 0..1
– A part cannot be part of more than one whole by composition
29
Composition
Example
– The following diagram illustrates the difference between weak and
strong aggregations.
– An address book is made up of a multiplicity of contacts and contact
groups. A contact group is a virtual grouping of contacts; a contact may
be included in more than one contact group. If you delete an address
book, all the contacts and contact groups will be deleted too; if you
delete a contact group, no contacts will be deleted.
Association with no navigability

– The diagram records that:


– For each object of class Student there are six objects of class Module which are
associated with the Student;
– For each object of class Module there are some Student objects (the number of
students is unspecified) associated with the Module.
Navigability

 We can put an arrow on one or both ends of the association


line to represent that it is possible for messages to be sent
in the direction of the arrow

 We say that Module knows about Student, but not vice


versa.
Constraints
– A constraint is a condition that has to be satisfied by any
correct implementation of a design
– A restriction or condition on an element.
– It is visualized in text between braces; for example: { size >= 0 }.
Interfaces in Class Diagram
 UML provides several ways to show interface implementation
 A set of signatures of public operations.
 In the UML, interface implementation is formally called interface realization
Example
Example: library management system
36
For any query Feel Free to ask!

You might also like