[Home] [Up]

E-methods: design pattern examples

The following are two examples of E-methods design patterns.

Check-Pre-Post

Consider a class C for which some extenders are defined. Instances of C have an internal state and some methods of C modify it. For each method m() that modify the state, it is useful to notify the extension object what is happening.

A convenient way to do so is to declare in C three E-methods:

Check_m(...)
This E-method is called before any change in the state takes place. The purpose of this E-method is to check if the action is allowed. Each extension object can throw an exception if his constraints are violated. No extension object modifies its state during the execution. Thus if some extension throws an exception, the internal consistency is not compromised.
Pre_m(...)
This E-method is called before the state of the support changes.
In the execution of the semantic definition, extension objects can modify their state, but cannot throw exceptions.
Post_m(...)
This E-method is called after the state of the support changes.
In the execution of the semantic definition, extension objects can modify their state, but cannot throw exceptions.

Pre-Step-Post

Consider a class C for which there are extenders. Each instance of C contains a set of objects belonging to the same class, we refer to them as the elements. Extension objects add information to that elements. For example, a graph contains a set of vertices; an extender that menages vertex labelling adds a string to each vertex.

A method m() performs an output in which all the stored information is shown. Part of that information is managed by the extension objects. Output must contain information about extension, too.

m() is implemented as a cycle over the vertices. The body of the cycle performs an output operation for each vertex. m() emits a header before all vertices. It consist of general information about the object. The following pattern can be used:

Pre_m(...)
It performs output releted to the whole extension object (i.e. generic information to put in the header)
Step_m(...)
It performs output releted to a single element.

[Home] [Up]