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

When can I use a forward declaration?

617


How do I start a c++ project?

583


What is the purpose of templates in c++?

562


What are friend functions in C++?

614


Explain the properties and principles of oop.

524






What is void pointer in c++ with example?

589


How can I improve my c++ skills?

552


On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?

671


Const char *p , char const *p What is the difference between the above two?

652


What is a template in c++?

631


What methods can be overridden in java?

665


Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

1483


the first character in the variable name must be an a) special symbol b) number c) alphabet

599


What is c++ array?

543


What is static function? Explain with an example

553