Unit2 Notes Divya
Unit2 Notes Divya
Topics:
Advanced object and class concepts, Asoociation ends, N-ary association
Aggregation, Abstract classes, Multiple inheritance, Metadata
Reification, Constraints, Derived data, Packages
State Modeling: Events, States, Transitions and Conditions;
State diagrams; State diagram behavior; Practical tips.
Multiplicity for an attribute specifies the number of possible values for each instantiation of an attribute.
A person has one name, one or more addresses, zero or more phone numbers, and one birthdate.
Scope
Scope indicates if a feature (attribute & operation) applies to an object or a class.
An underline distinguishes feature with class scope (static) from those with object scope.
Our convention is to list attributes and operations with class scope at the top of the attribute and operation
boxes, respectively. But it is not encouraged model.
Association ends
What is an association end? What are the properties of an association end?-----------6/8M
N-ary Association
An N-ary association is association among 3 or more classes.
But we should try to avoid n-ary associations- most of them can be decomposed into binary
associations, with possible qualifiers and attributes.
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 in italics next to the diamond.
Figure 2 above shows ternary association: A professor teaches a listed course during a semester. The
resulting delivered course has a room number and any number of textbooks. In n-ary association there is
atmost one link for each combination of Professor,Semester, and ListedCourse & there is one
DeliveredCourse.
Aggregation
What is aggregation and composition? Give their respective UML notations, with an example.----------------
--10M
In figure above, A LawnMover consists of a Blade, an Engine, many Wheels and a Deck. Here
LawnMover is assembly and other parts are called constituents.
Propagation of Operations
Propagation (triggering) is the automatic application of an operation to a network of objects when the
operation is applied to some starting object.
A person owns multiple documents
each document consists of paragraphs
paragraphs consists of characters.
The copy operation propagates from documents to paragraphs to characters.
The copy operation does not propagate in the reverse direction.
A small arrow indicating the direction and operation name is written next to the affected association.
Abstract Classes
Abstract class is a class that has no direct instances but whose descendant classes have direct instances.
Fig: Concrete superclasses must be avoided. One way to eliminate concrete superclasses is to introduce
other subclass as shown below.
Multiple Inheritance
Multiple inheritance allows a class to have more than one superclass and to inherit features from all parent
classes.
The advantage of multiple inheritance is
greater power in specifying classes by extending the base class
an increased opportunity for reuse
Disadvantage:
loss of conceptual and implementation simplicity.
Multiple Classification
An instance of a class is inherently an instance of all ancestors of the class.
For example, an instructor could be both faculty and student. One instance happens to participate in two
overlapping classes.
a. Multiple classification
List and explain the various restructuring techniques used with respect to workarounds-------10M
***Workarounds
Dealing with lack of multiple inheritance is really an implementation issue.
There are various restructuring techniques used with respective to workarounds:
1. Delegation using composition of parts (it uses delegation)
2. Inherit the most important class and delegate the rest (it uses delegation)
3. Nested generalization
Here first 2 approaches use delegation.
Delegation is an implementation mechanism by which an object forwards an operation to another object for
execution.
1. Delegation using composition of parts:
A superclass with multiple independent generalization as a composition in which each constituent
part replaces a generalization.
Inheritance of operations across the composition is not automatic.
The composite (employee) must catch operations and delegate them to the appropriate part.
3. Nested generalization:
This approach multiplies out all possible combinations.
This preserves inheritance but duplicates declarations and code and violets the spirit of OO
programming.
Metadata
Metadata is data that describes other data.
For example, a class definition is a metadata.
Models are inherently metadata
Many real-world applications have metadata, such as parts catalogs, blueprints, and dictionaries.
Figure above shows metadata and data. A Car model has a model name, year, base price and a
manufacturer.
Examples of Car Model: 1969, Ford Mustang & 1974, Volkswagen Rabbit.
A physical car has serial number, colour, options & owner.
Examples of physical Car: John owns blue Ford with serial number IFAJP and a red Volkswagen
with serial number 7E8IF.
A car model describes many physical cars and holds common data. Therefore, car model is metadata
relative to a physical car.
Reification
Define reification. Explain it with a diagram.------------------------6M
Reification is the promotion of something that is not an object into an object.
Constraints
What is a constraint with respect to a class modeling? Explain
Constraint is a condition involving model elements, such as objects, classes, attributes, links, associations,
and generalization sets.
A Constraint restricts the values that elements can assume.
1. Constraints on objects:
a. No employees salary can exceed the salary of the employees boss (a constraint
between two things at the same time.)
b. No Window can have the aspect ratio (length/width) of less than 0.8 or greater than
1.5(a constraint between attributes of a single object.)
c. The priority of the job may not increase(constraint on the same object over time)
2. Constraints on generalization sets
3. Constraints on Links
Multiplicity is a constraint on the cardinality of a set.
o Multiplicity for an association restricts the number of objects related to a given object.
o Multiplicity for an attribute specifies the number of values that are possible for each
instantiation of an attribute.
Qualification also constraints an association. A qualifier attribute disambiguates the objects for a
many association ends.
An association class implies a constraint. An association class is a class, it can have attribute
and operations, participate in associations, and participate in generalization.
The constraint {ordered} indicates that the elements of a many association end have an explicit
order that must be preserved.
Explicit constraint : The chair of a committee must be a member of the committee; the ChairOf
association is the subset of the MemberOf association.
Derived Data
A derived element is a function of one or more elements, which in turn may be derived.
Classes, associations, and attributes may be derived.
The notation for a derived element is a slash in front of the element name along with constraint that
determines the derivation.
Packages
A package is a group of elements (classes, association, generalization, and lesser packages) with a
common theme.
A package partitions a model, making it easier to understand and manage.
Large applications may require several tiers of packages.
Packages form a tree with increasing abstraction toward the root, which is the application, the top-
level package.
Notation for pakage is a box with a tab.
Prepare a class diagram for a graphical document editor that supports grouping.
Assume that a document consists of several sheets. Each sheet contains drawing objects, including
text, geometrical objects and groups. A group is simply a set of drawing objects, possibly including
other groups. A group must also contain at least two drawing objects. A drawing object can be a
direct member of at most one group. Geometrical objects include circles, ellipses, rectangles, lines,
and squares.
Events
An event is an occurrence at a point in time
Example: user depresses left button or Air Deccan flight departs from Bombay.
An event happens instantaneously with regard to time scale of an application. One event may logically
precede or follow another, or the two events may be unrelated.
Events include error conditions as well as normal conditions.
Three types of events:
1. signal event
2. change event
3. time event.
Signal Event
A signal is an explicit one-way transmission of information from one object to another.
An object sending a signal to another object may expect a reply, but the reply is a separate signal under the
control of the second object, which may or may not choose to send it.
A signal event is the event of sending or receiving a signal.
Divya, Asst. Professor, ISE dept., VCET, Puttur Page 18
ADVANCED CLASS MODELING, STATE MODELING
Signal can be grouped into signal classes and give each signal class a name to indicate common
structure and behavior.
The UML notation is the keyword signal in guillemets (<< >>) above the signal class name in the
top section.
The second section lists the signal attributes.
Change Event
A change event is an event that is caused by the satisfaction of a Boolean expression.
UML notation for a change event is keyword when followed by a parenthesized Boolean expression.
Time Event
Time event is an event caused by the occurrence of an absolute time or the elapse of a time interval.
1. UML notation for an absolute time is the keyword when followed by a parenthesized expression
involving time.
2. The notation for a time interval is the keyword after followed by a parenthesized expression that
evaluates to time duration.
States
A state is an abstraction of the values and links of an object.
UML notation for state- a rounded box containing an optional state name, list the state name in
boldface, center the name near the top of the box, capitalize the fist letter.
Event
represents points in time.
Eg: power turned on power turned off power turned on
State represents intervals of time.
Eg: Powered Not powered
State Diagrams
Give general UML system for state diagram & explain. ---------------------------5M
Explain with a diagram, the basic UML syntax for state diagrams.---------------8M
Define state diagrams and state model. Draw the state diagram for telephone line with activities.--------------
--------8M
A state diagram is a graph whose nodes are states and whose directed arcs are transitions between states.
State names must be unique within the scope of a state diagram.
All objects in a class execute the state diagram for that class, which models their common behavior.
A state model consists of multiple state diagrams one state diagram for each class with important temporal
behavior.
State diagrams interact by passing events and through the side effects of guard conditions.
UML notation for a state diagram is a rectangle with its name in small pentagonal tag in the upper
left corner.
The constituent states and transitions lie within the rectangle.
If more than one transition leaves a state, then the first event to occur causes the corresponding
transition to fire.
If an event occurs and no transition matches it, then the event is ignored.
If more than one transition matches an event, only one transition will fire, but the choice is
nondeterministic.
What do you mean by states and events? Draw the state diagram for telephone line system.--------6M
An alternate notation is to indicate initial and final states through entry (hollow circle) and exit
points(circles enclosing an x) .
2) Do-Activities:
A do-activity is an activity that continues for an extended time.
Do-activity can occur only within a state and cannot be attached to a transition.
Example : the warning light may flash during the paper jam state for a copier machine.
3) Activities on transitions: are the activities that are bound to an event that causes a transition.
Figure shows the control of garage opener. The user generates the depress events with a push button to
open and close the door. The control generates motor up and motor down activities for the motor. The
motor generates door open and door close events when the motion(opening/closing) has completed.
5) Self-transition: is a transition in which the source and target states are the same.
self-transition causes both the entry and exit activities will be executed
event within a state will not cause the entry and exit activities to be executed.
Divya, Asst. Professor, ISE dept., VCET, Puttur Page 25
ADVANCED CLASS MODELING, STATE MODELING
6) Completion Transition:
Completion transitions are triggered upon completion of an activity in the source state.
They are indicated by an arrow without any event name or label on them.
It fires automatically upon the completion of the activity associated with the source state.
7) Sending signals:
An object can perform the activity of sending a signal to another object.
A system of objects interacts by exchanging signals.
The activity send target.S(attributes) sends signal S with the given attributes to the
target object or objects.
A signal can be directed towards an object or a set of objects.
Target refers to the class of the objects that are targets of the event
Phone line sends a Connect(phone number) signal to the switcher when a complete phone number
has been dialed.
Explain state diagrams. Draw the state model for telephone line with activities.--------10M
A simple digital watch has a display and two buttons to set it, the A button and the B button. The
watch has two modes of operation, display time and set time. In the display time mode, the watch
displays hours and minutes, separated by a flashing colon. The set time mode has two sub modes, set
hours and set minutes. The A button selects modes. Each time it is pressed, the mode advances in the
sequence: display, set hour, set minutes, display, etc. Within the sub modes, the B button advances
the hours or minutes once each time it is pressed. Buttons must be released before they can generate
another event. Prepare a State diagram of the watch.-------------------------10M
Answer: