The Name of the Class
When I showed you the sieve of Eratosthenes class, I claimed that the name of the class was CSieve. That was a lie. The real name of the class is 0F590920-F220-11CE-8D2E-00AA004A5C59. How convenient. Wouldn’t it be fun to program like the code shown below:
Dim sieve As New 0F590920-F220-11CE-8D2E-00AA004A5C59
That’s essentially what C++ and B-- programmers have to do. Every class and every interface has its 128-bit identifier that is normally shown as a hexadecimal number with dashes at seemingly random dividing points. This is obviously too confusing, even for C++ masochists. Instead of using the full name, C++ programmers use constants such as CLSID_SIEVE for classes and IID_SIEVE for interfaces. The B-- language supports the same feature with a special GUID type, which can be initialized with a constant like this:
Const CLSID_SIEVE = 0F590920-F220-11CE-8D2E-00AA004A5C59
Keep in mind that the hexadecimal representation of the class identifier (class ID) is just a crutch for weak human memories. The real name is 128 bits of memory arranged in a UDT that looks like this:
Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
You might remember that we actually filled one of these GUIDs with a magic number back in Chapter 8.
Why can’t we just call our class CSieve? Well, one reason is that someone else might want to use the name CSieve. Maybe they’re wrapping the sieve of Pythagoras, or perhaps their sieve class sifts flour and baking soda. We want our class names to be simple and obvious, but the more simple and obvious they are, the more likely it is that they will duplicate someone else’s simple and obvious name. So behind every simple class name there’s a GUID, which brings us to the first principle of GUIDs.
Let me indulge readers from my part of the world by describing the pronunciation of GUID as geoduck without the “uck.” Those of you who don’t know a geoduck from a mallard can just say “Goo-Id.”