Methods and Properties

Objects are conceptually simple enough to understand, but it often takes people awhile to understand the difference between methods and properties. Luckily, it is not critical that you understand the difference and eventually it sinks in and makes perfect sense. In fact, you could just lump them all together and refer to them collectively as members of an object.

In a nutshell, properties are the characteristics that describe an object and methods are the actions that the object can perform. Consider where you live. You could call this a Residence object. A Residence object would have a property called Type, which may indicate that your residence is a house, apartment, or condo. It would also have an Owned property, which would be True if you owned your residence or False if you rented. The list below represents other properties your Residence object might have.




Square Feet


Methods are actions that an object can perform. For example, your Residence object may have a Cool method that cools the house (using the AirConditioner object) and a Heat method the heats the house (using the Furnace object). Many times, but not always, using an object's method alters one or more of that object's properties. For instance, the Cool and Heat methods would change the Temperature property. If you had a Renovate method, perhaps you could change the Bedrooms and Square Feet properties. Unfortunately the Renovate method would probably require quite a bit of cache, er, I mean cash.

Collection Objects

Collections are objects that exist to serve as containers for objects of a given type. The Residence object has two collection objects: Bedrooms and Bathrooms. Bedrooms is a way to collectively refer to all of the bedrooms in a given residence. Another way to describe this is that the Bedrooms collection is a collection of Bedroom objects.

Collection objects generally have special properties and methods that you can use to manage the collection. Usually there is an Add method, an Item method, and a Remove method. The Item method is used to retrieve a specific object from the collection. You can refer to an object in a collection either by name or number. For example, the following two statements would achieve the same result—initializing a Bedroom variable with a Bedroom retrieved from the Bedrooms collection:

Set BedroomVariable = Residence.Bedrooms.Item(l)

Set BedroomVariable = Residence.Bedrooms.Item("JoesRoom")

Collection objects always have a Count property that returns the number of items in a collection.

0 0

Post a comment