Sunteți pe pagina 1din 8


* Advanced object and Class

Advanced Class Modeling • Enumerations :-
-> Data type is a description of values. Data type
include numbers, strings, and enumerations.
-> An Enumeration is a type that has a finite set of
-> fig shows an example
-> We may display the possible values with a pick
list and We restrict data to the legitimate values.

-> Do not use a generalization to capture the values • Multiplicity :-

of an enumerated attribute.
-> Multiplicity is a constraint on the cardinality of a
-> We can use generalization only when at least set.
one subclass has significant attributes, operations,
-> We know that Multiplicity applies to an
or associations that do not apply to the superclass.
Association. It is also possible to apply Multiplicity
-> Ex..
Ex Card
we shouldn’t
shouldn t introduce a generalization to attributes.
for Card, because most games do not differentiate
-> Multiplicity for an attribute specifies the
the behavior of spades, clubs, hearts, and
number of possible values for each instantiation of
an attribute. [Use, DataBase applications].
-> In the UML, an enumeration is a data type. We
-> Some specifications are, mandatory single value
can declare an enumeration by listing the keyword
[1], Optional single value [0..1], and many [*].
enumeration in guillmets (<<>>) above the
enumeration name in the top section of a box. The -> If not specified, it is assumed to mandatory
2nd section lists the enumeration values. single value [1]. Ex.. Fig.

• Scope :- • Visibility :-
-> The Scope indicates if a feature applies to an -> Visibility refers to the ability of method to
object or a class. reference a feature from another class and has the
possible values of public, private, protected and
-> An Underline distinguishes features with class
scope (static) from those with object scope.
• Any method can freely access Public features.
-> Our
O convention
i is
i to list
li attributes
ib andd
operations with class scope at the top of the • Only methods of containing class can access
attribute and operation boxes, respectively. private features.
-> Ex.. Fig , A Phone Mail System will define some • Only methods of the containing class and its
different rules/constraints based on, which descendants via inheritance can access protected
merchants product we are using. Ex.. Reliance, features.
Indicom and so on. So these attributes must be
• Methods of classes defined in the same package
defined in their respective object scope, which
as a target class can access package features.
varies depending on the model we are using.


-> The UML denotes visibility with a prefix. -> Comprehension : We must understand all public
1) The character “+” precedes public features. features to understand the capabilities of a class.
Ignoring rest.
2) The character “#” precedes protected features.
-> Extensibility : Many classes can depend on public
3) The character “-” precedes private features. methods, so it can be highly disruptive to change
4) The character “~” precedes package features. their signature.
5) The lack of prefix reveals no info. About visibility. -> Context : Applied out of context, a private
method may calculate incorrect results or cause the
-> There are several issues to consider when object to fail.
choosing visibility.
-- Comprehension
-- Extensibility
-- Context

-> Aggregation : The association end may be an

* Association Ends aggregate or constituent part. Only a binary
association can be a constituent.
An Association end is an end of association. A -> Changeability : This property specifies the
binary association has two ends, a ternary update status of an association end. The
association has three ends, and so forth. possibilities are changeable (can be updated) and
-> Properties readonly
d l ((can only l b
be initialized).
l d)
• Association End Name -> Navigability : Conceptually, an association may
be traversed in either direction, however, an
• Multiplicity implementation may support only one direction.
• Ordering The UML shows navigability with an arrowhead on
• Bags and Sequence the association end attached to the target class.
• Qualification Arrowheads may be attached to zero, one, or both
ends of an association.

-> Visibility : Similar to attributes and operations,

association ends may be public, private, protected * N-ary Associations
and package.
-> N-ary associations are the associations among
three or more classes.
-> We should try to avoid n-ary associations, which
can be decomposed into binary associations. Ex..
-> Ex.. Fig , is a genuine n-ary association:
Programmer use computer languages on projects.
This n-ary association is an atomic unit and can’t be
subdivided into binary associations without losing
-> The UML symbol for n-ary associations is a
diamond with lines connecting to related classes.


-> If the association has a name, it is written italics -> Fig shows another ternary association. A
next to the diamond. Professor teaches a listed course during a semester.
The resulting delivered course has a room number
-> End names are necessary if a class participates
and any number of textbooks.
in an association more than once.
-> The Typical programming language cannot
-> We can’t traverse n-ary associations from one
express n-ary associations. Thus if you are
end to another as with binary association.
programming, you will need to promote n-ary
-> The OCL does not define notation for traversing associations to classes as Ex fig.
n-ary associations.
-> Be aware that you change the meaning of
model, when you promote an n-ary association to a

• Aggregation vs. Association

* Aggregation
-> Fig shows Ex.. For aggregation.
-> Aggregation is a strong form of association in
which an aggregate object is made of constituent -> If two objects are tightly bound by a part-whole
parts. relationship, it is an aggregation. If two objects are
usually considered as independent, even though
-> An assembly with many kinds of constituent
they may often be linked, it is an association.
parts corresponds
d to many aggregation.
-> some tests include
-> The most significant property of aggregation is
transitivity – i.e., if A is a part of B and B is a part i) Would you use the phrase part of?
of C, then A is a part of C. ii) Do some operations on the whole automatically
apply to its parts?
Aggregation is also antisymmetric, i.e., if A is a
iii) Do some attribute values propagate from the
part of B, then B is not a part of A.
whole to all or some parts?
Many aggregate operations imply transitive closure iv) Is there any intrinsic asymmetry to the
* and operate on both direct and indirect parts. association, where 1-class is subordinate to other.

-> Aggregation is drawn like association, except a -> The notation for composition is a small solid
small diamond indicates the assembly end. diamond next to the assembly class (vs. a small
• Aggregation vs. Composition hallow diamond for the general form of
-> The UML has two forms of part-whole
relationship; a general form called aggregation and -> Ex.. Fig, a Company of divisions, which in turn
a more restrictive form called composition. consist of departments; a company is indirectly a
composition of departments.
-> Composition is a form of aggregation with two
additional constraints.
i) A constituent part belong to at most one
ii) Once a constituent part has been assigned an
assembly, it has a coincident lifetime with the


• Propagation of operations * Abstract Classes

-> Propagation (triggering) is the automatic -> An abstract class is class that has no direct
application of an operation to a network of objects instance but whose descendant classes have direct
when the operation is applied to some starting instances.
-> A concrete class is a class that is instantiable;
>EEx.. M
i an aggregate
t moves itits parts;
t The
Th that
h is,
i it
i can have
h direct
di instances.
move operation propagates to the parts.
Only concrete classes may be leaf classes in an
-> The operation does not propagate in the reverse inheritance tree.
-> Ex fig , Worker class can be both abstract and
-> Ex fig, the copy operation propagates from concrete class.
documents to paragraphs to characters.
-> Any class with a Abstract operation/only the
-> Note that this notations is not part of UML and is signature of the operation [without implementation]
a special notation. is called abstract class.

-> In the UML notation an abstract class name is -> In the UML notation an abstract operation is
listed in an italic font. Or we may place the keyword listed in an italic font. Or we may place the keyword
{abstract} below or after the name. {abstract}.
-> Ex for an abstract class, ComputePay is an -> It is a good idea to avoid concrete superclasses.
abstract operation of class Employee; its signature. Fig shows, We can always eliminate concrete
but not
ot its
ts implementation
p e e tat o is s defined.
de ed Each
ac subclass
subc ass superclasses
supe c asses by introducing
t oduc g an
a Ot
e subc
must supply a method for this operation.
-> An abstract class can define the signature for an
operation without supplying a corresponding
method. It is called as abstract operation.
-> An abstract operation defines the signature of an
operation for which each concrete subclass must
provide its own implementation.

* Multiple Inheritance • Kinds of Multiple Inheritance

-> Multiple Inheritance permits a class to have

more than one superclass and to inherit features -> Fig Ex1, The most common form of inheritance
from all parents. is from set of disjoint classes. Each subclass inherits
-> If we try
y to distinguish
g between g
generalization from one class in each set.
(the conceptual) and Inheritance (the language -> The advantage of multiple inheritance is greater
mechanism), but the term “multiple inheritance” is power in specifying classes and an increased
more widely used than the term “multiple opportunity for reuse.
-> The dis-advantage is a loss of conceptual and
implementation simplicity. Or retains redundant
features of superclass in subclass.


• Multiple classification
-> Fig Ex2, Multiple inheritance can also occur in
overlapping classes. -> For Ex.., an instructor could be both faculty and
student. But what about a Harvard Professor taking
-> The UML uses a constraint to indicate an
classes at MIT [Massachusetts Institute of
overlapping generalization set;
Technology]. There is no class to describe the
the notation is a dotted line cutting
g across the combination. This is an example of multiple
affected generalizations with keywords in braces. classification.
In the ex.., overlapping means that an individual -> The UML permits multiple classification, but most
vehicle may belong to more than one of the OO language handle it poorly.
-> The best approach using conventional languages
Incomplete means that all possible subclasses of is to treat Person as an object composed of multiple
vehicle have not been explicitly named. UniversityMember objects. This workaround
replaces inheritance with delegation [group
representing others].

-> This is not totally satisfactory, because there is a i) Delegation using composition of parts:
loss of identity between the separate roles.
-> We can recast a superclass with multiple
• Workarounds independent generalizations as a composition in
-> Dealing with lack of multiple inheritance is really which each constituent part replaces a
an implementation issue, but early restructuring of generalization.
a model is often the easiest way to work around its -> Ex.. fig.., An operation sent to an Employee
absence. object would have to be redirected to the
EmployeeEmployment or EmployeeManagement
-> Two of the approaches make use of delegation, part by the Employee class.
which is an implementation mechanism by which an -> This approach replaces a single object having a
object forwards an operation to another object for unique ID by a group of related objects that
execution. compose an extended object.
1. Delegation using composition of parts -> In this approach, All combinations of subclasses
2. Inherit the most important class and delegate the from the different generalizations are possible.

i) Inherit the most important class and delegate -> Any of these workarounds can be made to work,
the rest: but all compromise logical structure and
-> fig 4.19, preserves identity and inheritance maintainability. There are several issues to consider
across the most important generalization. when selecting the best workaround:

We degrade the remaining generalizations to 1.Superclasses of equal importance: If a subclass

composition and delegate their operations as in the has
as several
se e a superclasses,
supe c asses, all
a ofo equal
equa importance,
po ta ce, itt
previous alternative. may be best to use delegation and preserve
symmetry in the model.
-> Nested generalization:- Factor on one
generalization first, then the other. This approach 2.Dominant superclass: If one superclass cleanly
multiples out all possible combinations. dominates and the other are less important,
preserve inheritance through this path.
Ex.. Fig.., This preserves inheritance but duplicates
declarations and code and violates the spirit of 3.Few Subclasses: If the number of combinations is
OOProgamming. small, consider nested generalization. If the number
of combinations is large, avoid it.


4.Sequencing generalization sets: If we use nested * Metadata

generalization, factor on the most important
criterion first, the next most important second, and -> Metadata is data that describes other data.
so forth. For ex.. A Class definition is a metadata.

5.Large quantities of code: Try to avoid nested -> Many real-world applications have metadata,
generalization if you must duplicate large quantities such as catalog, dictionaries.
of code. -> Fig shows, an ex.. For metadata and data.
6.identity: Consider the importance of maintaining A car model has a model name, year, basePrice, and
strict identity. Only nested generalization preserves manufacturer. Some ex.. For car model are 1969
this. Ford Mustang.
A physical car has a serial number, color, options,
and an owner. Ex.. John Doe may own a blue ford
with serial number 1FABP.

-> A car model describes many physical cars and * Reification

common data.
-> Reification is the promotion of something that is
-> A car model is metadata relative to a physical not an object into an object.
car, which is data.
-> Reification is helpful technique for meta
-> Classes are meta-objects and not real-world applications because it lets you shift the level of
bj t b because objects
bj t provides
id values
l ffor th
the abstraction.
attributes defined by a class.
-> It is useful to promote attributes, methods,
-> In other words, Class descriptor objects have constraints, and control information into objects, so
features, and they in turn have their own classes, we can describe and manipulate them as data.
which are called metaclasses.
-> fig Reification, promotes the substanceName
If we assume, that a classes as objects, it mean attribute to a class to capture the many-to-many
that, it is referencing to some class. Such a class is relationship between Substance and
called Metaclasses. substanceName.

-> For ex.., propylene may be referred to as * Constraints

propylene and C3H6.
Also, an alias may pertain to multiple chemical -> A Constraint is a boolean condition involving
substances. Various mixtures of ethylene glycol and model elements, such as objects, classes,
automotive may have the alias of antifreeze. attributes, links, associations, and generalization
-> We can express constraints with natural
language or formal language such as the Object
Constraint Language [OCL].
-> A Constraint restricts the values that elements
can assume.


• Constraint on Objects • Constraint on Generalization set

-> Fig shows, examples of constraints. -> The UML defines the following keywords for
generalization sets.
-> No employee’s salary can exceed the salary of
the employee’s boss (a constraint b/w two things at i) Disjoint, The subclasses are mutually exclusive.
the same time). Each object belongs to exactly one of the
b l
-> No window can have an aspect ratio
(length/width) of less than 0.8 or greater than 1.5 ii) Overlapping, The subclasses can share some
(a constraint b/w attributes of a single object). objects. An object may belong to more than one
-> The priority of a job may not increase
(constraints on the same object over time). iii) Complete, The generalization lists all the
possible subclasses.
-> We may place simple constraints in class models.
iv) Incomplete, The generalization may be missing
some subclasses.

• Constraint on Links -> The UML has two alternative notations for
constraints. We can either delimit a constraint with
braces or place it in a “dog-eared” comment box,
-> Multiplicity for association and Multiplicity for which can be connected to the constrained elements
attributes using dashed lines.

> Qualification also constraints an association.
association -> Ex.. Fig..

-> A Association class implies a constraint.

-> The constraint {ordered}, {bags}, {sequence}.
-> Fig shows an explicit constraint that is not part
of the model’s structure. The ChairOfassociation is a
subset of the MemberOf association.

* Derived Class * Packages

-> A Derived element is a function of one or more -> A Package is a group of elements (classes,
elements, which in turn may be derived. associations, generalizations, and lesser packages)
with a common theme.
-> Classes, associations, and attributes may be
derived -> A package partitions a model
model, making it easier to
understand and manage.
-> The notation for a derived element is a slash in
front of element name. We should also show the -> Large application requires a tiers of packages.
constraint that determines the derivation.
-> Fig.. Shows, the notation for a package is a box
-> Fig.. Ex1, derived attribute. with a tab.
-> Fig.. Ex2, derived class and derived class. -> The purpose of the tab is to suggest the
enclosed contents, like a tabbed folder.


-> Themes for forming packages

-> Tips for devising packages
-> Use of constraint
-> Ternary Assosiation