| |||||||||||
|
Main Menu Other |
Tutorials -- Working with Objects | ||||||||||
|
Working with Objects Using ClassesEncapsulation is probably a word you've heard a lot about if you've read anything on C++ programming. So what the heck is it? It means grouping variables and functions into a "class", so that they can be re-used as different "instances" of that class. Think of a class as though it were a blueprint for a house. A blueprint can be reused to make several houses, all with similar features but maybe different properties (ex. colored walls or different style of windows). But a blueprint isn't a house, is it? Nope, it's simply a reusable plan for a house. To take this further, lets use this analogy to explain subclassing. Say we want two types of blueprints. One blueprint we'll keep the same as it originally was, and one we want to add a backyard swimming pool to. It would be downright stupid to make a whole new blueprint just to add the pool. We'd want to use the same blueprint, which has all the same properties of the other houses made with it, but this time we'll add the pool to it. This is how subclassing works. Instead of making a whole new blueprint, we reuse them to add on specific things. Instead of rewriting the same functions for each class, we reuse them to add on specific properties. Hopefully this has cleared up any confusion with classes and subclassing. Move on to learn how to define classes and make instances of classes.
|
|||||||||||