docs.roxen.comView this page in a printer friendly mode
DocsPike7.0TutorialObject-Oriented Programming
Copyright  2012, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com
 DEMO  DOCS  PIKE
 COMMUNITY  DOWNLOAD
www.roxen.com



Object Orientation in General
Object Orientation in Pike
Creating and Using Objects
How to Create a Class
Classes as Record Types
Programs are Classes and Vice Versa
Inheritance
Multiple Inheritance
Access control

Object Orientation in Pike

Just like most other object-oriented languages, Pike has classes, objects, inheritance, constructors, and so on. In Pike, a source file can be used as a class definition. Class and program are synonyms.

Programs Within Programs: Object-Oriented Pike

As we have said before, a class is a description of a type of thing. You can clone the class to create objects. Each object is a clone (sometimes called instance) of the class.

A class contains some variables, which are sometimes called member variables. The variables are attributes or characteristics of the objects, and each object will have its own set of the member variables. For example, if the class animal has the member variables name and weight, then each animal will have those two variables, so each animal can have a name and a weight.

A class also contains some methods. (C++ programmers would call them "member functions".) The methods describe things that the objects can do.

For example, if the class "animal" has the method eat, then you can call that method in any animal, to make it eat. Well, of course it won't really eat, since it's just some data in the computer and not a real animal. But the method can change the member variables, for example by increasing the value of weight for that animal.