SourcePro Net : Essential Networking Module User’s Guide : PART II The Networking Package : Portals : Understanding the Portal and Implementation Classes
Understanding the Portal and Implementation Classes
Figure 6 shows the public classes in the Portal Layer and the fictional user-defined classes MyCustomPortal and MyCustomPortalImp.
Figure 6 – Portal layer classes
RWPortal is a portable, transport-independent, communications class. It is designed using the interface-implementation idiom. The interface class, RWPortal, is a simple interface to the underlying communications channel. It includes functions for reading and writing unbuffered data to and from a communications channel.
The implementation base class, RWPortalImp, is an abstract class that includes an interface for the operations that RWPortal needs. RWPortalImp is used only by the RWPortal objects that reference it -- your applications should never directly access the implementation objects. Classes derived from RWPortalImp, including user defined classes, implement the operations defined by the RWPortalImp interface.
Each RWPortal is associated with one RWPortalImp located on the heap. The Networking package uses reference counting so that multiple RWPortal objects can refer to the same underlying implementation object. The RWPortal copy constructor and assignment operator create shallow, lightweight copies through their implementation object. When all the portals that refer to a particular implementation object have gone out of scope, the implementation object’s destructor is called (often this closes the communication channel) and the implementation object is deleted from the heap.