Part of the ObjectBasedProgramming Pattern Language. Discussions on InstanceDataDiscussion.
Original at http://www.geocities.com/SiliconValley/Foothills/5962/instancedata.htm
Intent
Provide a basis for encapsulation and polymorphism.
Motivation
This section is to be filled in.
Applicability
This Instance Data pattern is applicable when
The attributes and all other intrinsic states of an object, transient and otherwise, are captured and encapsulated into an instance data. The design and structure of the instance data is opaque to the outside world. The structure is visible only to the functions implementing the operations of the class family.
Typically the instance data is stored in one or more data structures. If the instance data is stored in more than one instance data structure, the principal data structure must provide references to the other data structures.
Consequences
The Instance Data pattern has four important consequences:
Consider the Non-Leaf alarm class.
[1]
An object of the non-leaf alarm class has the following attributes:
Description ChangeCount? DescendentChangeCount? State Identifier ParentAlarm? NextSiblingAlarm? FirstChildrenAlarm?The following code segment shows an example design of the instance data structure to encapsulate the state of a non-leaf alarm.
typedef struct { char abDescription[10], int nChangeCount, int nDescendentChangeCount, BOOL bstate, tsOID sIdentifier, int nParentAlarmHandle, int nNextSiblingAlarmHandle, int nFirstChildAlarmHandle, } tsNON_LEAF_ALARM;Known Uses
The Instance Data pattern is fundamental to the application of object-based programming style described in this pattern language. This pattern has been extensively applied in the Network Management Unit Software (NUS) developed by MAS Technology. The Management Procedure Lock, the Condition Manager and the object handlers are implemented with the application of this pattern.
I have used this pattern (with this name even) for developing a plugin architecture where the plugin shared library exports a CeeLanguage interface for what is effectively a CeePlusPlus object in the main program. This was done because the symbol naming standards for C are much simpler than for C++.
The FILE pointer in the CeeLanguage stdio standard library is another example of InstanceData.
Related Patterns
The FamilyFusion pattern and the FamilySplit pattern describe two common techniques to design an instance data structure.
The instance data structure may include operation pointers if the FunctionPointer pattern is applied.
Dynamic typing information, if required, is provided by the ClassTag pattern.