What are proxy objects in C++?


Objects that stand for other objects are called proxy objects or surrogates. template <class t=""> class Array2D
{ public:
class Array ID
{
public:
T& operator[] (int index);
const T& operator[] (int index)const;
};
Array ID operator[] (int index);
const Array ID operator[] (int index) const;
};

The following then becomes legal:
Array2D<float>data(l 0,20); cout«data[3][6]; // fine
Here data[3] yields an ArraylD object and the operator [] invocation on that object yields the float in position(3,6) of the original two dimensional array. Clients of the Array 2D class need not be aware of the presence of the ArraylD class. Objects of this latter class stand for one-dimensional array objects that, conceptually, do not exist for clients of Array2D. Such clients program as if they were using real, live, two-dimensional arrays. Each ArraylD object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, ArraylD is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist.

0 comments:

Post a Comment

Blogger news