Objects, Properties and Methods – An Analogy

In this blog post we provide an analogy to help conceptualise objects, properties and methods and the way in which they interact.

Most people tend to understand that if you want to change the text in a command button you use the Caption property and if you want to change the back-color you use the BackColor property. It almost seems like killing a fly with a nuclear bomb to explain objects, properties and methods when, in truth, they can be quite intuitive. There is, alas, an ulterior motive behind these machinations!

The concepts surrounding object based languages and programming mean that it is very important that programmers are not only able to use objects, properties and methods but are also able to understand the thinking behind them.

Note: Taking some time now to really get to grips with these ideas will pay dividends in the future.

So, here we provide you with an analogy and for this particular analogy we shall be using a car!

The Car Object

Cars are objects. Cars can contain other objects like a Wheel object and a Bonnet object. These objects can contain other objects themselves such as a Tire object for the Wheel object.

 

VBA works much the same way. A Form object can contain a Command Button object or a Combo-Box object or a Text-box object.  And just as a Form is part of a collection, so too can controls be part of a collection.

 

Taking the car analogy a little further we can make some observations about the car above:

 

  • The Car Object contains a Door Object.
  • The Door object is part of a collection (Doors).
  • The count property of the Door object is 2 (There are 2 doors).
  • The Door object has a Color property.
  • The Color Property of the Door object is set to Orange.
  • The Door object contains a Window object.
  • The Window object has a Broken property.
  • The Broken property of any of the Window objects in this Car object is set to False (None of the windows are broken).
  • The Car has a Drive Method.

 

Get the idea? Objects are things that have attributes (properties) and things they can do (Methods). These concepts can be a little confusing at first but are worth persevering with as they will provide you with the base to go on and master VBA (and other programming languages).

 

 

Related Posts

Normalization
What is Microsoft Access?

As always, a site wouldn't be anything without its users so please feel free to comment! We welcome any comments you have on the material and any suggestions you may have for future content.


In our humble opinion, it is worth commenting just so you can play with Fun Captcha below!