Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 1.3

COLUMN

Advanced Techniques

Object Oriented Programming in REALbasic

Issue: 1.3 (December/January 2002)
Author: Thomas Reed
Author Bio: Thomas Reed has been programming as a hobbyist for more than 20 years, and fell in love with the Mac in 1984.
Article Description: No description available.
Article Length (in bytes): 11,758
Starting Page Number: 30
Article Number: 1315
Resource File(s):

Download Icon 1315.zip Updated: 2013-03-11 19:07:56

Related Link(s): None

Excerpt of article text...

When you work in REALbasic, there is no escaping from object-oriented programming (OOP). Everything you do centers around objects -- windows, controls, and even your own custom classes. Nonetheless, there is much more lurking under the surface of REALbasic's classes than is immediately evident. This column will look at several facets of OOP like class inheritance, method overloading, and class interfaces.

Inheritance

One of the most important concepts in any object-oriented approach is inheritance. Inheritance allows you to create new classes that are based on existing classes, thus allowing you to reuse existing code. For example, suppose you are writing a simulator program in which you create a Vehicle class, which includes information about velocity, among other things. If you want to add a Car class to the simulator, it is easy to create Car as a subclass of Vehicle. The new class inherits all properties and methods of the super (or parent) class, and can also define its own properties and methods. For example, your Car class should have methods for dealing with movement provided by the Vehicle parent class, and might extend that by adding methods for trunk capacity, engine type, sunroof, and number of doors.

In REALbasic, you can set your custom class' parent class using the Super field of the Properties window. In some OOP languages, such as C++, a class can inherit from multiple other classes (this is called multiple inheritance), but in REALbasic it can only inherit from one. This is not much of a problem though, thanks to class interfaces (covered later).

An instance of a class is also considered to be an instance of all of its parent classes. A Car is not just a Car, it's also a Vehicle. You can pass a Car object to a method that takes a Vehicle as a parameter for example, allowing you to write generalized routines that can act on all types of Vehicle. If you need to find out what specific type of Vehicle it is, you use the "isa" keyword like this:

Sub WhatIsThis(v as Vehicle)

...End of Excerpt. Please purchase the magazine to read the full article.