This an example of conflating policies. It is one of the most useful feature in designing. It is highly customizable and several behavior aspects of design can be formulated with ease. The Smart Pointer has two design implementations with two policies: Threading model and Checking policy before dereferencing the SmartPtr. The template has three arguments: a pointer of class T, Threading Model and Checking Policy. Implementing several policies the SmartPointer could be defined with typedef. The two policies are:
Checking Policy: This policy introduces a check function with value of class T pointer ( T*). The SmartPtr invokes the Check member function. The template is CheckingPolicy<T>.
Threading Model: It includes a inner type function Lock, of type of class T reference (T&). The template would be ThreadingModel(T).
There are two types of Checking Polices included, NoChecking and EnforceNotNull. The types of threading models are SingleThreaded and MultiThreaded. The beauty of combining the policies is that SmartPtr::Operator-> behaves differently on two extraneous dimensions. As we can notice, it covers a huge band of combinatorial behavior in a small code snippet.
Comments