Joomla Files Webdesign Erfurt
Header Pic   Header Pic
Header Pic  PfeilHome arrow Key Concepts Header Pic
Header Pic

Key Concepts PDF Print E-mail
Encapsulation

Encapsulation simply means that an object "knows" what to do. For example, an EditField "knows" how to deal with text that the user inputs. It does not have to refer to any code outside itself. When you add properties and methods to an RB object, you add the properties and code to the object itself. This is seen when you open an object's code editor. All of the events, methods, properties, ect. are part of the object itself. In non-OOP programming languages this is not necessarily the case.

The advantage of encapsulation is that you can referencs an object's properties and methods easily using dot notation (see Using Dot Notation in the Tutorials section).

Inheritance

Inheritance allows you to create new objects based on existing RB objects. For example, let's say you want to have a PushButton that has a caption of "OK" instead of the default "Untitled". Here's how:

1. Add a class to your project by selecting New Class from the File menu.
2. Select this class in the project window.
3. In the Properties window set the name of the class to OKButton
4. Enter "PushButton" as the super
5. Double click on OKButton in the project window to open up its code editor window
6. Select the Open event and enter this code "me.caption = "OK"
Now, let's see how it works. Double click on a window in the project window to display the window.
Drag the OKButton class from the project window to the displayed window. It's caption will still be "Untitled" but that's okay. Run the project and you will see that the button has "OK" as its caption.

"But," you say, "Couldn't I have done the same thing by just setting the caption to "OK" in the properties window?" Yes, you could BUT the cool thing about your OKButton is that it can be used in all of your other projects as well as in the one where it was created! Drag your OKButton from the project window to your desktop. Taa daa! Now you can add an OKButton to any other project just by dragging your OKButton class to its project window.

This is just a very simple example of inheritance. It demonstrates that you can use existing RB objects and add features and functionality to them, then re-use the modified object in other projects. In this case we added an event to a PushButton but you can also add new properties and methods to objects.

The power of inheritance is that the new class you create has all of the properties and functionality of the object you choose as its "super". In our example, OKButton retained all of the characteristics (properties) of a PushButton. We didn't have to build an object from scratch. We could take the existing PushButton object and make it into our own special kind of pushbutton. Because of inheritance we can do this with any RB object (StaticText, EditField, Listbox, GroupBox, etc.).

Data Types

Computers treat different types of data differently. Numbers are not dealt with in the same way that words are. For example, to a computer 4 + 8 means "add 4 and 8" so the result is 12. However "4" + "8" means combine the character "4" and the character "8". In this case the result is the characters "48".

Here are some of the more common data types:
Integer: whole numbers (no decimals or fractions)

String: letters and numbers that are just characters Examples: Terry, This is a string, She is 15 years old, AER$643*9&HBY.

Boolean: this data type can be either True or False

There are several other data types but, as a beginner, these will be the types you will use most often.

In your program code you need to identify the type of data you are using so the computer will know how to deal with that data. This is done by using a "dim" statement at the beginning of the block of code. In the examples below the code and the result of executing the code are shown Image
 
Header Pic
left unten
right unten
(C) 2008 Really Basic REALbasic

W3C validiert