Object Oriented Programming:
The Object Framework provides the ability to create classes and objects (which
for LOGO thing would probably be a better name then object).
Classes:
Classes are like blueprints. If you have a blueprint for a house, it tells
you how to build a house but it isn't itself a house.
Objects:
In the above analogy, an object would be a house itself. You can use the
same blueprint to build any number houses.
Creating Classes:
To create a new class use the DefineClass procedure. The DefineClass
procedure takes one argument the name of the class you want to
create. For instance to create a class named house we would enter:
? DefineClass "house
Creating Objects:
Now we have created a class, we can create objects that are instances of
that class. To create an object of a class use the newclass procedure
to create an instance of that class, where class is the name of the
class. For instance, since our class is named house we will use the newhouse
procedure to create a new house object. Let's create two houses: myhouse and
yourhouse.
? newhouse "myhouse
? newhouse "yourhouse
Reporting instances of a class:
You can see all objects that have been created for a class. We will use
this later on in this tutorial, but I bring it up now while we are discussing
creating objects. To see all instances of an object use the classobjects
procedure. Since the name of our class is house we will use the houseobjects
procedure.
? show houseobjects
[myhouse yourhouse]
Class Predicates:
When you define a class, a predicate for that class is also created. You can use
this predicate to check to see if an object belongs to that class. To check if
an object belong to the class use the classobject? predicate.
Where class is the name of the class. So to check if an object is a
house, we would use the houseobject? predicate.
? show houseobject? "myhouse
true
? show houseobject? "yourhouse
true
? show houseobject? "ourhouse
false
Deleting Objects:
We have created two house objects. Let's now delete these objects.
To delete an object use the deleteclass command. Again, since the
name of our class is house, we will use the deletehouse procedure.
? deletehouse "myhouse
? show houseobjects
[yourhouse]
? deletehouse "yourhouse
? show houseobjects
[]
Deleting Classes:
Finally, let's delete the house class. To delete a class use the deleteclass
command. The deleteclass command takes one argument, the name of the
class you want to delete.
? deleteclass "house
In the next sections I will discuss Properties.
|