VBA provides class modules to enable you to enjoy many, but not all, of the benefits of object-oriented programming. So far throughout this book, you've been working with and enjoying the benefits of objects that other programmers have created. You've used the Application object, Workbook object, Worksheet object, and Range object, among others. I think you'd agree that using these objects seemed, for the most part, a natural experience. Well-designed objects feel natural to use because they have properties and methods that work and are named just as you'd normally think about them.

Although it is natural to use objects, many beginning programmers have a difficult time approaching objects from the other perspective—that is, as a developer of classes that will be used by yourself or other programmers. The terms class and object are often used in the same context. To be precise, however, a class is like an object template, whereas an object is a class that has been instantiated (created) using the object template (class). Objects are instantiated in VBA using the New keyword.

Part of the problem that beginning programmers may have with objects is that they haven't experienced some of the pain that object-oriented programming techniques can relieve. Therefore, it's harder to comprehend how the extra effort involved in developing classes is beneficial. That said, the extra effort is minimal. Classes are really not any more difficult to develop. They're just different. Remember, different doesn't equal difficult.

If you are still a little fuzzy on classes after this chapter, don't worry—practice makes perfect. In the next chapter, you'll get some more practice with classes by developing a class that you can use to, among other things, implement user personalization in your Excel application.

0 0

Post a comment