Professional Documents
Culture Documents
Lecture 6 SW
Lecture 6 SW
Structural Models
• Structural models depict the static view of a system
• Structural models represent system objects and their relationships:
• People, things, places, etc…
• Main goal: to discover the key data contained in the problem domain
and to build a structural model of the objects
Structural
Modeling
Solution Domain
Problem Domain
5
6
7
8
9
10
11
Class/Object Identification
Different approaches can be used to identify objects:
• Patterns
• Is a list of objects common to the business domain of the system.
• Useful groupings of collaborating classes that provide solutions to
common problems (are reusable)
• Developed patterns provide a starting point for work in similar
domains
Class Diagrams
• A static model that shows classes and their relationships to one
another. (classes remain constant over time)
• Elements of a class diagram:
• Classes
• Objects within the system (a person, place or thing)
• Stores and manages information in the system and contains:
• Attributes—characteristics of the class
• Operations (methods)—activities the class can perform
Class
• Classes
•Are general templates used to create specific instances
(objects) of people, places, or things.
•Concrete classes: application domain classes. E.g. employee
class.
•Abstract classes: do not actually exist in the real world. E.g.
person class.
• Attributes
•Properties that describe the state of an instance of a class
(an object)
•Only important and primitive types (e.g. int, string, double,
date, bool) should be added.
• Operations (methods)
•Actions or functions that a class can perform.
•Only problem-domain specific methods should be
considered.
Relationships
• Denotes associations between classes
• Depicted with a line labeled with the name of the relationship
• May be directional (depicted with a triangle; e.g., a patient schedules an
appointment)
Relationships
• Classes may be related to themselves (e.g., employees and
managers who may be members of the same class)
• A (+) sign is placed before the label to indicate its role.
• E.g. a patient can be the primary insurance carrier for other patients.
Relationships
• Describes how classes relate to one another
• Three basic types in UML
Generalization
• Enables inheritance of attributes and operations of other classes.
• Represents relationships that are “a-kind-of”, e.g. an employee is a kind of
person.
• Superclass/Subclass: subclasses can also contain attributes and operations
that are unique just to them.
Aggregation
• Relates parts to wholes
• Represents relationships that are “a-part-of”, e.g. an engine is part of a car.
• Decomposition: the opposite of aggregation. E.g. decompose a class into
subclasses.
Association
• Miscellaneous relationships between classes, usually a weaker form of
aggregation.
• E.g. a patient schedules an appointment.
19
Attributes
• Properties of a class
• E.g. Person: last name, first name, address, etc.
• We can use derived attributes (\), i.e. attributes that have been
calculated from other attributes.
• Visibility of an attribute:
• Restricts access to attributes to ensure consistency
• Public attributes (+): visible to all classes, not hidden from other
objects.
• Private attributes (-) {default}: hidden from all other classes,
visible only to an instance of the class in which they are defined.
• Protected attributes (#): attribute hidden from all other classes
except its immediate subclasses
25
Methods
• Common methods are not shown. E.g. Create() or delete() an
instance, Return() or set() a value.
• Only operations unique to the class are included. E.g.
cancelAppointment(), calculateLastVisit().
• Can also be public protected, or private {default}.
Association Classes
• A relationship itself has associated properties.
• Common in many-to-many relationships
• Used when attributes about the relationship between two classes
needs to be recorded
• Students are related to courses; a Grade class provides an attribute to
describe this relationship
• Illnesses are related to symptoms; a Treatment class provides an attribute
to describe this relationship
27
Class Diagram
28
Object Diagram
• A good way of
simplifying a
class diagram is
through an object
diagram.
• Also good when
used to provide a
real use-case
scenario.
Library Book Collection System
Library Book Collection System
Library Book Collection System
Simplifying Class Diagrams
• Fully populated class diagrams of real-world system can
be difficult to understand
Objects class
Time
inTi
hour minute Att
30
Me
void addMinutes( int m ) vo
outTime
Attributes: hour = 17 minute = 35
Methods:
void addMinutes(int m)
37
…
} constructor for Time
void
42
bill
Attributes: …
Methods:
…
43
bill
Attributes: …
Methods:
…
44
bill
Attributes: …
Methods:
…
inToWork
Attributes: hour = 8 minute = 30
Methods:
void addMinutes(int m)
45
inToWork.addMinutes(15)
bill
Attributes: …
Methods:
…
inToWork
Attributes: hour = 8 minute = 30
Methods:
void addMinutes(int m)
46
bill
Attributes: …
Methods:
…
inToWork
Attributes: hour = 8 minute = 45
Methods:
void addMinutes(int m)