### Creating Client-Local Objects

The client code in the previous topic showed only the case in which a class of objects is remote. However, many client applications also need to create and use local objects of the same class. The significant difference is that the local object is not created by way of a remote procedure call as is the remote object. The interface class generated by the IDL compiler from the interface definition is an abstract class. This means that another class must be derived from it to create and manipulate objects. The client stub has a proxy class automatically defined for remote objects, but your client application must define a local implementation class so that your client can create and manipulate local interface objects.

Do the following to create and use local versions of interface objects:

1. Derive a local class from the interface class to implement the client-local objects. This class is just like a manager class used in server development: in fact, this example uses the same manager class as the server.

2. Write the local code that implements the interface class. Our example uses the same manager code implementation as for the server. You implement the manager class by adding the code to the manager header file generated by the IDL compiler, or by deriving a new class from the manager class and implementing those functions.

3. Link the local class and local implementation code into your client application.

The following sample code shows how a client creates a local Matrix object:

#include "matrix.h" // IDL generated header file
#include "matrix_mgr.h" // local class implementation
.
.
.
Matrix *mlocal;
// Create a local Matrix object in this program
mlocal = new MatrixMgr(4, 3, 2, 1);
cout << "mlocal created:" << endl;
print(mlocal);
.
.
.

#include "matrix_mgr.h"
To implement client-local objects, the application includes a local manager class that is derived from the interface class. Local code is also linked to the application that implements the client-local objects.

mlocal = new MatrixMgr( ... )
Clients create a local object by using the C++ new operator on the local manager class defined in the matrix_mgr.h header file.

###