- The Class Hierarchy
- Creating a New Class
- Declaration and Instantiation
- Constructors and Destructors
- Garbage Collection
- Inheritance
- Object Operators
- Adding and Overriding Methods
- Calling the Overridden Method
- Overloading
- Casting
- Oddities
- Encapsulation
- Access Scope: Public, Private, Protected
- Setting Properties with Methods
- Default and Optional Parameters
- Declaring Variables Static and Const
- Revisiting the StringParser Module
- Example: Creating a Properties Class
- Data-Oriented Classes and Visual Basic Data Types
- Advanced Techniques
Creating a New Class
A new class is created just like a new module. Open up a new project in REALbasic and click the Add Class button and a new class will be added, as shown in Figure 3.2. However, App, Window1, and Menubar1 are classes, too. They are provided by REALbasic automatically, but everything you can do with this class we are about to create, you can do with them as well. These three classes will be covered in much more detail in the next two chapters.
Figure 3.2 Creating a new class in the REALbasic IDE.
After you create this new class, select it, and change the name to Alpha in the Properties pane on the right side of the window. Double-click the Alpha class in the Project Editor to bring up the Alpha tab, as shown in Figure 3.3.
Figure 3.3 Editing code for the Alpha class.
When you've done this, you'll see that you have additional buttons on the Code Editor toolbar. In addition to the familiar Add Method, Add Property, and Add Constant, you'll see Add Menu Handler and Add Event Definition. Menu Handlers and Event Definitions are special kinds of methods that I'll cover later.
The Alpha class won't do anything really useful. The purpose is to implement some methods and properties in such a way that you can see the different way that classes implement and use them. The first method to add is the getName method:
Function getName() as String Return "Alpha" End Function
As you can see, this method returns the string "Alpha" when it is called.