Declaring Classes

[This is preliminary documentation and subject to change.]

The MOF language can be used to define either new base classes and classes that derive from existing classes. To declare the most basic class, use the Class keyword with the name of your new class followed by a pair of curly braces and a semi-colon:

class ClassName
{
};

Class names must start with a letter and never an underscore. WBEM only allows system classes and system properties to start with an underscore. All remaining characters must be letters, digits, or underscores. WBEM recommends that you use a two-part name joined by an underscore. Specify your vendor name as the first part and a descriptive class name for the second part. For example, Acme_LogicalDisk describes the LogicalDisk class manufactured by Acme.

Most classes include properties to describe the data of the class. To declare a property, include the property's data type, name, and an optional default value between the curly braces as follows:

class MyClass 
{
    string   strProp;
    sint32   dwProp1 = 21;
    uint32       dwProp2;
}

The MyClass class has three properties: a character string, a 32-bit signed integer, and a 32-bit unsigned integer. As an option, a property can be assigned an initial value in the class declaration. Instances of a class inherit all of the properties of the class and any initial values. However, each instance can choose whether to accept these default values or override them with alternate values.

Methods are declared much like properties. The following sample illustrates how to declare a class that includes two methods: one that returns a 32-bit integer and another that has no return value. The VOID keyword can be used to indicate a method that does not have a return value.

class MyClass
{
    sint32  Method1 ();
    void    Method2 ([in] sint32 InParam);
};

Class definitions can be more complicated, including such MOF features as aliases and qualifiers. Default values can be assigned to properties and qualifiers using one of the MOF data types.