What are proxy objects?

Answer Posted / harendra pal

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

The following then becomes legal:
Array2D<float>data(10,20);
........
cout<<data[3][6]; // fine

Here data[3] yields an Array1D object and the operator [] invocation on that object yields the float in position(3,6) of the original two dimensional array. Clients of the Array2D class need not be aware of the presence of the Array1D 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 Array1D object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, Array1D is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many types of scopes are there in c++?

785


What is setiosflags c++?

706


How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?

769


What is std :: endl?

783


What is stl containers in c++?

773


How are Structure passing and returning implemented by the compiler?

828


Differentiate between realloc() and free().

767


Evaluate as true or false: !(1 &&0 || !1) a) True b) False c) Invalid statement

839


What is c++ namespace?

935


Is it possible to write a c++ template to check for a function's existence?

778


How does a C++ structure differ from a C++ class?

848


What is the first name of c++?

760


Explain how functions are classified in C++ ?

985


Define Virtual function in C++.

833


What are pointers used for c++?

779