Page 176 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 176
Principles of Software Engineering
Notes structures (like loops, conditionals etc). but a freer format for internal description. This allows
the designer to focus on the logic and not its representation in the programming language.
8.3.1 State Modelling of Classes
For object-oriented design for obtaining the thorough design can be used for designing the
logic of methods. But a class is not a functional concept such cannot be viewed as merely a
compilation of functions (methods).
The technique for getting a more detailed understanding of the class as whole, without talking
about the logic of different methods, has to be different from the refinement-based approach.
An object of a class has some state and many operations on it. To better understand a class, the
relationship between the state and various operations and the effect of interaction of various
operations has to be understood. This can be viewed as one of the objectives of the detailed
design activity for object-oriented development. Once the overall class is better understood, the
algorithms for its various methods can be developed.
A method to understand the behaviour of a class is to view it as a finite state Automaton, which
consists of states and transitions between states. When modelling an object, the state is the value
of its attributes, and an event is the performing of an operation on the object. A state diagram
relates events and status by showing how the state changes when an event is performed. A state
diagram for an object will generally have an initial state, from which all states are reachable (i.e.
there is a path from the initial state to all other states).
A state diagram for an object does not represent all the actual states of the object, as there are
many possible states. A state diagram attempts to represent only the logical states of the object.
A logical state of an object is a combination of all those states from which the behaviour of the
object is similar for all possible events. Two logical states will have different behaviour for at
least one event. For example, for an object that represents a stack. all states that represent a
stack of size more than 0 and less than same defined maximum are similar as the behaviour
of all operations defined on the stack will be similar in all such slates (e.g., push will add an
element, pop will remove, etc.). However, the state representing an empty stack is different as
the behaviour of top and pop operations are different now (an error message may be returned).
Similarly, the state representing a full stack is different. The state model for this bounded size
stack is shown in Figure 8.2.
Figure 8.2: The FSA Model of a Stack
pop/err–msg push
push pop
Empty Not–enpty– Full push
Stack not–full Stack err–msg
push
pop
push
The finite state modelling of objects is an aid to understand the effect of various operations
defined on the class on the state of the object. A good understanding of this can aid in developing
the logic for each of the operations. To develop the logic of operations, regular approaches for
algorithm development can be used. The model can also be used to validate if the logic for an
operation is correct.
170 LOVELY PROFESSIONAL UNIVERSITY