Software Engineering-The Object Behavior Model


The CRC model and the object-relationship model represent static elements of the OO analysis model. It is now time to make a transition to the dynamic behavior of the OO system or product. To accomplish this, we must represent the behavior of the system as a function of specific events and time.

The object-behavior model indicates how an OO system will respond to external events or stimuli. To create the model, the analyst must perform the following steps:

1. Evaluate all use-cases  to fully understand the sequence of interaction within the system.
2. Identify events that drive the interaction sequence and understand how these events relate to specific objects.
3. Create an event trace  for each use-case.
4.
Build a state transition diagram for the system.
5. Review the object-behavior model to verify accuracy and consistency.
Each of these steps is discussed in the sections that follow.

Event Identification with Use-Cases

The use-case represents a sequence of activities that involves actors and the system. In general, an event occurs whenever an OO system and an actor (recall that an actor can be a person, a device, or even an external system) exchange information. It is important to note that an event is Boolean. That is, an event is not the information that has been exchanged but rather the fact that information has been exchanged.

A use-case is examined for points of information exchange. To illustrate, reconsider the use-case for SafeHome :

1. The homeowner observes the SafeHome control panel to determine if the system is ready for input. If the system is not ready, the homeowner must physically close windows/doors so that the ready indicator is present. [A not-ready indicator implies that a sensor is open, i.e., that a door or window is open.]

2. The homeowner uses the keypad to key in a four-digit password. The password is compared with the valid password stored in the system. If the password is incorrect, the control panel will beep once and reset itself for additional input. If the password is correct, the control panel awaits further action.

3. The homeowner selects and keys in stay or away to activate the system. Stay activates only perimeter sensors (inside motion detecting sensors are deactivated). Away activates all sensors.

4. When activation occurs, a red alarm light can be observed by the homeowner.

The underlined portions of the use-case scenario indicate events. An actor should be identified for each event; the information that is exchanged should be noted; and any conditions or constraints should be listed.

As an example of a typical event, consider the underlined use-case phrase “homeowner uses the keypad to key in a four-digit password.” In the context of the OO analysis model, the object, homeowner, transmits an event to the object control panel. The event might be called password entered. The information transferred is the four digits that constitute the password, but this is not an essential part of the behavioral model. It is important to note that some events have an explicit impact on the flow of control of the use-case, while others have no direct impact on the flow of control. For example, the event password entered does not explicitly change the flow of control of the use-case, but the results of the event compare password (derived from the interaction “password is compared with the valid password stored in the system”) will have an explicit impact on the information and control flow of the Safe- Home software.

Once all events have been identified, they are allocated to the objects involved. Objects can be responsible for generating events (e.g., homeowner generates the password entered event) or recognizing events that have occurred elsewhere (e.g., control panel recognizes the binary result of the compare password event).

State Representations

In the context of OO systems, two different characterizations of states must be considered: (1) the state of each object as the system performs its function and (2) the state of the system as observed from the outside as the system performs its function.

The state of an object takes on both passive and active characteristics . A passive state is simply the current status of all of an object’s attributes. For example, the passive state of the aggregate object player  would include the current position and orientation attributes of player as well as other features of player that are relevant to the game (e.g., an attribute that indicates magic wishes remaining). The active state of an object indicates the current status of the object as it undergoes a continuing transformation or processing. The object player might have the following active states: moving, at rest, injured, being cured; trapped, lost, and so forth. An event (sometimes called a trigger) must occur to force an object to make a transition from one active state to another. One component of an object-behavior model is a simple representation of the active states for each object and the events (triggers) that cause changes between these active states. figure illustrates a simple representation of active states for the control panel object in the SafeHome system.

Each arrow shown in figure represents a transition from one active state of an object to another. The labels shown for each arrow represent the event that triggers the transition. Although the active state model provides useful insight into the “life history” of an object, it is possible to specify additional information to provide more depth in understanding the behavior of an object. In addition to specifying the event that causes the transition to occur, the analyst can specify a guard and an action . A guard is a Boolean condition that must be satisfied in order for the transition to occur. For example, the guard for the transition from the “at rest” state to the “comparing state” in figure can be determined by examining the use-case:

if (password input = 4 digits) then make transition to comparing state;

In general, the guard for a transition usually depends upon the value of one or moreattributes of an object. In other words, the guard depends on the passive state of the object.

An action occurs concurrently with the state transition or as a consequence of it and generally involves one or more operations (responsibilities) of the object. For example, the action connected to the password entered event is an operation  that accesses a password object and performs a digit-by-digit comparison to validate the entered password.

The second type of behavioral representation for OOA considers a state representation for the overall product or system. This representation encompasses a simple event trace model that indicates how events cause transitions from object to object and a state transition diagram that depicts the processing behavior of each object.

Once events have been identified for a use-case, the analyst creates a representation of how events cause flow from one object to another. Called an event trace, this representation is a shorthand version of the use-case. It represents key objects and the events that cause behavior to flow from object to object.

Figure  illustrates a partial event trace for the SafeHome system. Each of the arrows represents an event (derived from a use-case) and indicates how the event channels behavior between SafeHome objects. The first event, system ready, is derived from the external environment and channels behavior to the homeowner object. The homeowner enters a password. The event initiates beep and “beep sounded” and indicates how behavior is channeled if the password is invalid. A valid password results in flow back to homeowner. The remaining events and traces follow the behavior as the system is activated or deactivated.

Once a complete event trace has been developed, all of the events that cause transitions between system objects can be collated into a set of input events and output events (from an object). This can be represented using an event flow diagram . All events that flow into and out of an object are noted as shown in below figure  state transition diagram  can then be developed to represent the behavior associated with responsibilities for each class.

UML uses a combination of state diagrams, sequence diagrams, collaboration diagrams, and activity diagrams to represent the dynamic behavior of the objects and classes that have been identified as part of the analysis model.
Share this article :
 
Copyright © 2012. Best Online Tutorials | Source codes | Programming Languages - All Rights Reserved