Instance Data

Part of the ObjectBasedProgramming Pattern Language. Discussions on InstanceDataDiscussion.

Original at


Provide a basis for encapsulation and polymorphism.


This section is to be filled in.


This Instance Data pattern is applicable when Solution

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.


The Instance Data pattern has four important consequences:

  1. Encapsulation. As the instance data contains all intrinsic states of an object, the instance data completely describes the state of the object. In other words the instance data becomes synonymous to the object. An external entity interacting with this object needs only reference to the instance data, without any knowledge of the internal structure.

  2. Operations take instance data as input. The polymorphic functions implementing the operations must take the instance data as an parameter.

  3. Scaleable. As the intrinsic states of an object are encapsulated in the instance data, the functions implementing the operations no longer have to store the states of the objects they operate on. As a result the functions do not have inherent limits on the number of objects they can operate on.

  4. De-coupled from storage management. In a tradition procedural implementation, a sub-system typically assumes part or full responsibility of the storage of the information. The procedural implementations typically make assumptions about the storage of information. This unnecessary coupling reduces the reuse value. The Instance Data pattern however de-couples the object-based functions from the storage management of the instance data. The functions do not know how the instance data is created and managed. The implementation is therefore more portable and flexible.

Sample Code

Consider the Non-Leaf alarm class.


An object of the non-leaf alarm class has the following attributes:








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,

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.

View edit of November 19, 2012 or FindPage with title or text search