10.4 Operations


The operations defined by a class specify how the data may be manipulated. Generally speaking, a complete set of primitive operations maximizes reusability. A set class template typically provides operators such as add item or set, remove item or subset, and test for item or subset membership. Even if the current application doesn't use all these operations, adding the complete list of primitives makes it more likely to meet the needs of the next system.

Analysis models abstract class operations into object messages (class, object, sequence, and collaboration diagrams), state event acceptors (statecharts), and state actions (statecharts). The great majority of the time, these messages will be directly implemented as operations in the server class using the implementation strategy for the association supporting the message passing (see the previous section).

Analysis and early design models only specify the public operations. Detailed design often adds operations that are only used internally. These operations are due to the functional decomposition of the public operations. For example, a queue might provide the following set of public operations:

 template <class T, int size> class queue { protected:     T q[size];     int head, tail; public:     queue(void): head(0), tail(0);     virtual void put(T  myT);     virtual T get(void); }; 

A cached queue caches data locally but stores most of it on a more remote, but larger data store, such as a hard disk. Operations can be added to implement the caching so that it is invisible to the client, maintaining LSP:

 template <class T, int size> class cachedQueue : public queue<T, size> { protected:     void writeToDisk(void);     void readFromDisk(void); public:     cachedQueue(void): head(0), tail(0);     virtual void put(T  myT);    // new version uses                                  // writeToDisk                               // when cache fills     virtual T get(void);         // new version uses                                  // readFromDisk                                  // when data is not                                     cached }; 

These operations are added to support the additional functionality of the cachedQueue subclass.

Functional decomposition of operations is shown in structured methods using structure charts. Since the UML does not provide structure charts, activity diagrams should be used instead.



Real Time UML. Advances in The UML for Real-Time Systems
Real Time UML: Advances in the UML for Real-Time Systems (3rd Edition)
ISBN: 0321160762
EAN: 2147483647
Year: 2003
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net