This document discusses various concepts related to class modeling in object-oriented design, including:
1. Classes describe groups of objects that share properties, behaviors, and relationships. Class diagrams model classes and their relationships.
2. Associations describe relationships between classes, such as links between objects. Association ends, multiplicity, and qualified associations add more detail to associations.
3. Generalization allows subclasses to inherit and specialize features of superclasses, supporting polymorphism and code reuse through inheritance.
2. CONTENTS:
1. Object and Class Concepts.
2. Link and Association Concepts
3. Generalization and Inheritance
Class Modeling
Computer Department SPIT, Piludara
3. Object:
•It is a concept, abstraction, or a thing with identity
that has meaning for an application .
•Each have identity and are distinguishable.
•Two apples with the same color, shape, and
texture are still individual apples; a person can eat
one and then eat the other.
•Similarly, identical twins are two distinct persons,
even though they may look the same.
1. Object and Class Concepts:
Computer Department SPIT, Piludara
4. Class:
•Describes a group of objects with the same
properties( attributes), behavior (operations), kinds
of relationship, and Semantics. (Eg: Person,
company, Process and Window )
•Each person has name and birthdate and may work
at a job.
•Objects in a class have the same attributes and
forms of behavior.
Classes
Computer Department SPIT, Piludara
5. Class Diagram:
• Provide a Graphical notation for modeling classes and their
relationships, thereby describing possible objects as shown
in figure 1.
Object Diagram:
• Shows individual Objects and their relationships.
Class Diagrams
Computer Department SPIT, Piludara
6. • Class diagrams are useful both for abstract modeling and for
designing actual programs.
• A class diagram corresponds to an infinite set of object
diagrams.
• Object diagrams are helpful for documenting test cases and
discussing examples.
• In fig. the UML symbol for an object is a box with an object
name followed by a colon and the class name.
• The object name and class name are both underline.
Class Diagrams
Computer Department SPIT, Piludara
8. Operations:
•It is a function or procedure that may be applied to or
by objects in a class as shown in figure.
•Hire, fire, and payDividend are operations on class
Company.
•Open, close, hide and redisplay are operations on
class Window.
•All objects in a class share the same operations.
Operations and Methods
Computer Department SPIT, Piludara
9. Polymorphic
• Same operation applied to many different class.
• That is the same operations takes on different forms in different
classes
Methods:
• It is a implementation of an operation for a class.
• For example, the class File may have an operation print.
• To implement different methods to print ASCII files, print binary
files and print digitized picture files.
• All these methods logically perform the same task- printing a
file.
Operations and Methods
Computer Department SPIT, Piludara
10. Signature:
• it is important that the methods all have the same signature –
the number and types of arguments and the type of result
value.
• For example, print should not have filename as argument for
one method and file pointer as argument for another.
Feature:
• Generic word for either an attribute or operation.
Operations and Methods
Computer Department SPIT, Piludara
12. Summary of Notation for Classes
Computer Department SPIT, Piludara
•The compartments in the box contain, from top to bottom: class
name, list of attributes, and list of operations.
•Optional details are type, default values, argument list and result
type may follow each operation name.
13. direction argumentName : type = defaultValue
• Each argument may have a direction, name, type, and
default value.
• The direction indicates whether an argument is an input (in),
output (out), or an input argument that can be modified
(inout).
• A colon precedes the type. An equal sign precedes the
default value.
• The default value is used if no argument is supplied for the
argument.
Summary of Notation for Classes
Computer Department SPIT, Piludara
14. Link:
•It is a physical / conceptual connection among objects.
•For example, Joe Smith Works For Simplex company.
•Most links relate two objects, but some links relate three or
more object.
Association:
•It is a description of a group of links with common structure
and common semantics.
•For example, a person WorksFor a company .
•The links of an association connect objects from the same
classes.
•An association describes a set of potential links in the same
way that a class describes a set of potential objects.
Link and Associations
Computer Department SPIT, Piludara
15. 2. Link and Association Concepts:
Computer Department SPIT, Piludara
16. •The UML notation for a link is a line between objects.
•An association connects related classes and is also denoted
by a line. For example, persons own stock in companies.
•In fig. show link and association names in italics and to
confine line segments to a rectilinear grid.
•The association name is optional, if the model is
unambiguous.
•Ambiguity arises when a model has multiple associations
among the same classes (person works for company and
person owns stock in company).
•When there are multiple associations, use association names
or association end names to resolve the ambiguity.
Link and Associations
Computer Department SPIT, Piludara
17. •Associations are inherently bidirectional.
•The name of the binary association usually reads in a
particular direction, but the binary association can be
traversed in either direction.
•For example, WorksFor connects a person to a company.
The inverse of WorksFor could be called employee, and it
connects a company to a person.
•Both directions of traversal are equally meaningful and refer
to the same underlying association.
Link and Associations
Computer Department SPIT, Piludara
18. Reference:
•It is an attribute in one object that refers to another object.
•For example, a data structure for Person might contain an
attribute employer that refers to a Company object, and a
Company object might contain an attribute employees that
refers to a set of Person objects.
•A link is a relationship among objetcs.
Link and Associations
Computer Department SPIT, Piludara
19. Multiplicity:
• Specifies the number of instances of one class that may relate
to single instance of other class.
• Multiplicity constrains the number of related objects.
•UML specifies: “1”: exactly one,“1 ..*” (one or more),
“3..5” (three to five inclusive)
• The special symbol “*” is a shorthand notation that denotes
“many” (zero or more).
• In fig. shows a one-to-one association and some
corresponding links. Each country has one capital city.
• A capital city administers one country.
Multiplicity
Computer Department SPIT, Piludara
22. • In fig. show a Workstation may have one of its windows
designated as the console to receive general error messages.
(The word “console” on the diagrams is an association end
name)
• Multiplicity is a constraint on the size of a collection and
Cardinality is the count of elements that are actually in a
collection.
• Therefore, multiplicity is a constraint on the cardinality.
• A multiplicity of “many” specifies that an object may be
associated with multiple objects.
Multiplicity
Computer Department SPIT, Piludara
24. Association End names:
• Association End names is an important concept in UML.
• Association ends can not only be assigned multiplicity they can
also be named. In a problem description they are generally
identified by nouns
• For example, a one-to-many association has two ends – an
end with a multiplicity of “one” and an end with a multiplicity of
“many”.
• In fig. shows, a name appears next to the association end.
In fig. Person and Company participate in association
WorksFor . A person is an employee with respect to a
company, a company is an employer with respect to a person.
Association End Names
Computer Department SPIT, Piludara
25. • Use of Association End names is optional, but it is often
easier and less confusing to assign association end name
instead of , or in addition to, association names.
Association end:
• Can give names to the association link.
Use of associations end name:
• to name links b/w object of same class.
Association End Names
Computer Department SPIT, Piludara
27. • Association End names are necessary for associations two
objects of the same class.
• For example, in fig.11 container and contents distinguish the
two usages of Directory in the self-association.
• Association End names can also distinguish multiple
associations between the same pair of classes.
• In fig. 11 each Directory has exactly one user who is an
owner and many users who are authorized to use the
directory.
• When there is only a single association between a pair of
distinct classes.
Association End Names
Computer Department SPIT, Piludara
29. • In fig. shows, in the wrong model, two instances represent a
person with a child, one for the child and one for the parent.
• In the correct model, one person instance participates in two
or more links, twice as a parent and zero or more times as a
child.
• In the correct model, we must show a child as having an
optional parent, so that the recursion eventually terminates.
• No association end name should be the same as an attribute
name of the source class.
Association End Names
Computer Department SPIT, Piludara
32. Bag:
• It is a collection of elements with duplicates allowed.
Sequence:
• Ordered collection of elements with duplicate allowed.
• For example, An itinerary is a sequence of airports and the
same airport can be visited more than once.
• Sequence is ordered bag both allow duplicates, {ordered}
and {sequence} is same only difference is sequence allows
duplicates as shown in figure 14.
Bags and Sequences
Computer Department SPIT, Piludara
34. • It is an association that is also a class.
• Like the links of an association, the instances of an
association class derive identity from instances of the
constituent classes.
• Like a class, an association class can have attributes and
operations and participate in associations.
• You can find association classes by looking for adverbs in a
problem statement or by abstracting values.
• In fig.15, AccessPermission is an attribute of AccessibleBy.
• The sample data at the bottom of the fig. shows the value for
each link. The UML notation for an association class is a box
(a class box) attached to the association by a dashed line.
Association Classes
Computer Department SPIT, Piludara
36. • Many-to-many associations provide a compelling rationale for
association classes.
• In fig.15, AccessPermission is a joint property of File and
User and cannot be attached to either File or User alone
without losing information.
• In fig.16 presents attributes for two one-to-many associations
• Each person working for a company receives a salary and
has a job title.
• The boss evaluates the performance of each worker.
• Attributes may also occur for one-to-one associations.
Association Classes
Computer Department SPIT, Piludara
39. • In fig.17 shows how it is possible to fold attributes for one-to-
one and one-to-many associations into the class opposite a
“one” end. This is not possible for many-to-many associations.
• In fig. 18 shows an association class participating in an
association.
• 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.
Association Classes
Computer Department SPIT, Piludara
41. • In fig.19 shows the difference. The association class has only
one occurrence for each pairing of Person and Company.
• In ordinary class there can be any number of occurrence of a
Purchase for each Person and Company.
• Each Purchase is distinct and has its own quantity, date and
cost.
Association Classes
Computer Department SPIT, Piludara
43. • An association in which an attribute called the qualifier
disambiguates the objects for a “many” association end.
• Job of qualifier is to reduce the many association to one. Can
only work for m-m and 1-m.
• Also facilitates traversal of class models
• Stock exchange gives special unique symbol to each
company
• Using qualified association we can make traversal easy.
• Ref Figure 20,21.
Qualified Association
Computer Department SPIT, Piludara
44. • In fig.20 show the most common use of a qualifier – for
association with one-to-many multiplicity.
• A bank services multiple accounts. An account belongs to a
single bank. Within the context of a bank, the account
number specifies a unique account.
• Bank and Account are classes and AccountNumber is the
qualifier.
• Qualification reduces the effective multiplicity of this
association from one-to-many to one-to-one.
• Both models are acceptable, but the qualified model adds
information. The qualified model adds multiplicity conctraint,
that the combination of a bank and an account number yields
at most one account.
Qualified Association
Computer Department SPIT, Piludara
46. • In fig.23 show a stock exchange lists many companies.
• However, a stock exchange lists only one company with a
given ticker symbol.
• A company may be listed on many stock exchanges, possibly
under different symbols.(If every stock had a single ticker
symbol that was invariant )
Qualified Association
Computer Department SPIT, Piludara
48. • Generalization is the relationship between a class (the super
class) and one or more variations of the class (sub class)
• Super class holds the common attributes, operations and
associations. Subclass adds specific attributes, operations,
and associations.
• Each subclass inherits features of super class.
• Generalization is some times called the “is-a” relationship,
because each instance of a subclass is an instance of the
superclass as well.
• There can be multiple levels of generalizations.
Generalization and Inheritance
Computer Department SPIT, Piludara
49. • Generalization is the relationship between a class (the super
class) and one or more variations of the class (sub class)
• Serves three purposes
• Support for polymorphism. (call at super class level
automatically resolved)
• Second purpose is to structure the description of objects.( a
taxonomy is formed)
• Third purpose is to enable reuse of code.
• The terms generalization, specialization and inheritance all
refer to aspects of the same idea.
• Generalization: derives from the fact that the superclass
generalizes the subclasses.
Use of Generalization
Computer Department SPIT, Piludara
50. • Specialization: refers to the fact that the subclasses refine or
specialize the Superclass.
• Inheritance: is the mechanism for sharing attributes,
operations, and associations via generalization /
specialization relationship.
Overriding Features:
• A subclass may override a super class feature by defining a
feature with the same name.
• We can override methods and default values of attributes.
• Never override the signature, or form, of a feature.
Use of Generalization
Computer Department SPIT, Piludara