The SOM run-time environment contains the basic data structures and functions that are used to define, create, and manage classes and objects in terms of other classes.
Note: OS/2 operating system Version 3 includes SOM 2.1 run time and Workstation DSOM. The OS/2 Version 3 Toolkit contains a subset of the SOMobjects* 2.1 Toolkit.
Classes are generic definitions of sets of objects and their behaviors. Classes are defined at compilation time. Class objects are the SOM run-time implementation of SOM classes. Because the terms class and class object refer to the same thing, but in different contexts (compilation time and run time), they can be used interchangeably. Objects are created dynamically during run time. Objects are instances of classes. The methods that an object responds to are referred to as instance methods, because any object instance can perform them. An object's instance methods are defined in its class definition, and cannot be used unless an object instance already exists. Object instances are created by methods that operate on the class object to make it produce an object instance. Class methods that create object instances are called factory methods or constructors. SOM classes that define factory methods for classes are called metaclasses. Metaclasses are classes of classes. A class object is an instance of its metaclass.
The relationship between objects, classes, and metaclasses is shown in the following figure.
Only One of These Only One of These ┌───────────┐ ┌──────────────┐ │ The │ │ The Object's │ ┌──────│ Object's │────────│ Metaclass, │ Many of These │ │ Class, "C │ │ "M" │ ┌──────────────┐ │ └───────────┘ └──────────────┘ ┌┴────────────┐ │ │ ┌─┴───────────┐ │ │ │ Defined here are Defined here are ┌┴───────────┐ │ │ ├─────┘ instance methods class methods │ An │ │ │─┘ for class "C" that for class "M" that │ Object, │ │─┘ operate on objects operate on class │ "O" │─┘ "O" (instances of (object) "C" to └────────────┘ class "C"). cause it to produce instances of "C".
The SOM environment can be created automatically or explicitly within any process that uses it. SOM supplies three classes, as shown in the following table. Classes that make up the SOM run-time environment are packaged with the operating system in SOM.DLL.
┌──────────────────────────────┬──────────────────────────────┐ │Object │Description │ ├──────────────────────────────┼──────────────────────────────┤ │SOMClass │Root class for all SOM │ │ │metaclasses. │ ├──────────────────────────────┼──────────────────────────────┤ │SOMClassMgr │Class for SOMClassMgrObject. │ ├──────────────────────────────┼──────────────────────────────┤ │SOMObject │Root class for all SOM │ │ │classes. │ └──────────────────────────────┴──────────────────────────────┘
SOMObject defines the essential behavior common to all SOM objects. All SOM classes are subclasses of SOMObject. SOMClass defines the essential behavior common to all SOM class objects. SOMClass is a subclass of SOMObject and is the metaclass of the SOMObject class. By definition, SOMClass is its own metaclass. SOMClassMgr is the class definition for the SOMClassMgrObject that is created during SOM initialization. During SOM initialization, four objects are created, as shown in the following figure. Three of these objects are class objects.
┌──────────────┐ ┌───────────────┐ │ SOMObject │───────│ SOMClass │ │ Class Object │ ┌───│ Class Object │ └──────────────┘ │ └───────────────┘ ┌─────────────────┐ ┌──────────────┐ │ │SOMClassMgrObject│──────│ SOMClassMgr │ │ └─────────────────┘ │ Class Object │───┘ └──────────────┘
The SOMClass class object provides constructors for SOMObject class objects and for the SOMClassMgr class object. SOMObject defines a set of methods common to all SOM objects. Because all classes are subclasses of SOMObject, they inherit the set of methods common to all SOM objects. SOMClassMgrObject is an instance of the SOMClassMgr class object. SOMClassMgrObject dynamically loads and unloads class libraries when referenced and tracks instances of class objects.