Instancing

You might recall from the section on Naming the Class, that I promised to explain the Instancing property. Well, now it's time.

A class's Instancing property defines whether the class is private or public (see Figure 12-23).

Properties - cIsKennel

| cIsKennel ClassModule ^

Alphabetn: Categorized

| cIsKennel ClassModule ^

Alphabetn: Categorized

(Name)

cIsKennel

Instancing

Si - Privai-p^^^B

ยก2 - PutilicNcitCreatablefi

Figure 12-23

Setting a class's Instancing property to Private means that the class can only be used within the application in which it is defined.

Setting it to PublicNotCreatable means that although other applications can access type library information about the class, they can use it only after your application has created it first; they can't create instances of it.

Classes that have their Instancing property set to PublicNotCreatable are referred to as dependent objects, and typically form part of more complex objects. Using our Kennel/Dog example, you might want to allow an external application to create multiple Kennel objects, but only allow Dog objects to exist as a part of a Kennel. To do that, you make the Dog class PublicNotCreatable and let the user add new Dogs by adding a Dogs collection to the Kennel class. That way, they can only create new Dogs using the collection's Add method.

0 0

Post a comment