Relationships
[Previous] [
Next
]
Relationships
The relationship between all Object By Value design pattern
participants
is as
follows
:
-
A sender process creates a PersistableObject object and maintains a reference to an ObjectTransformer object and a Conduit mechanism. Using the ObjectTransformer object, the sender process initiates the action to extract the state of its PersistableObject to a data stream and sends the stream on its way down the Conduit mechanism.
-
A recipient process retrieves the data stream at the other end of the Conduit and, with the help of an ObjectTransformer object, converts the stream back into a copy of the original object.
NOTE
A Conduit mechanism is used to transport a data stream from point A to point B. This mechanism could be one of a number of technologies, such as COM, MSMQ, HTML, or MAPI.
Figure 6-1 (next section) illustrates the course of required events to pass or return an object by value.
[Previous] [Next]
Ramifications
Passing or returning an object by value results in the following consequences:
-
Supports sharing of object copies between systems using different types of objects
A key participant of the Object By Value design pattern is the ObjectTransformer class. It would not be too difficult to envision using a Conduit mechanism (such as COM or MSMQ) that is supported by dissimilar object systems to transport a data stream. Once the data stream is accepted by the recipient process, a native object transformer could produce a copy of the original object by correctly implementing the object conversion specification you, as the designer, set forth. For example, a Visual Basic object transformer could convert a Visual Basic object to a data stream, and a Pascal object transformer could convert the stream into a Pascal object copy of the original Visual Basic object.
-
Encapsulates the internal state of an object
Because the data stream is a byte array, you are not forced to explicitly expose the state of an object by deprivatizing that object. The persistable object contains the inherent functionality for updating its state from a byte array.
-
No compile-time type checking
Because the data stream is a byte array, there is no type checking at compile time. Therefore the potential for sending a byte array of invalid data to a recipient process is possible, wasting
valuable
processing cycles.
-
Passing an object by value is not a language feature
Although not terribly difficult to implement, significant programmer intervention and cooperation is required to
adhere
to the specification defined for implementation of the Object By Value design pattern.