Page384
In our case, the programmer simply needs to program Addy to support the method of addition (inheritance takes care of everything else Addy must know). Fig. 9.8 shows Addy adding two numbers.
The “Addy” object.
“1 + 2” is the input message; “3” is the output message. Addy also supports delegation: if he does not know how to perform a requested function, he can delegate that request to another object (called “Subby” in Fig. 9.9).
Delegation.
Addy also supports polymorphism (based on the Greek roots “poly” and “morph,” meaning many and forms, respectively): he has the ability to overload his plus (“+”) operator, performing different methods depending on the context of the input message. For example: Addy adds when the input message contains “number+number”; polymorphism allows Addy to concatenate two strings when the input message contains “string+string,” as shown in Fig. 9.10.
Polymorphism.
Finally, polyinstantiation means “many instances,” two instances (specific objects) with the same names that contain different data. This may be used in multilevel secure environments to keep top secret and secret data separate, for example. See Chapter 4, Domain 3: Security Architecture and Engineering for more information about polyinstantiation. Fig. 9.11 shows polyinstantiated Addy objects: two objects with the same name but different data. Note that these are two separate objects. Also, to a secret-cleared subject, the Addy object with secret data is the only known Addy object.
Polyinstantiation.
Here is a summary of Object-Oriented Programming concepts illustrated by Addy:
- Object: Addy
- Class: Mathematical operators
- Method: Addition
- Inheritance: Addy inherits an understanding of numbers and math from his parent class mathematical operators. The programmer simply needs to program Addy to support the method of addition
- Example input message: 1 + 2
- Example output message: 3
- Polymorphism: Addy can change behavior based on the context of the input, overloading the “+” to perform addition, or concatenation, depending on the context
- Polyinstantiation: Two Addy objects (secret and top secret), with different data