• Description:
    OOP (Object Orientd Programming) is a kind of programming, which is much safer, than normal programming. This is because in the OOP is used for each object it's own function, which is programmed exactly for the object.

  • Classes:
    Class is defined in the same way as OBJECT. To make a class from a normal object, You have to assign to the class (object resp.) some method(s). See below how to make it. Items of class can be accessed inside methods directly without need to use the pointer to the class.
      OBJECT myclass
        name[16]:CHAR,
        age:CHAR,
        sex:CHAR
      

    This is a small class, which has three items name, age and sex.

  • Constructors and destructors:
    Each OOP class (object resp.) must be somehow created at the beginning and somehow deleted at the end of it's usage. Constructor is a special function (method resp.), which allocates a memory for the object and clears it to be ready for usage. Currently allocation and clearing is the only operation, that the constructor does. When the constructor created the class, You can use it how ever You wish. And when everything is finished, You have to call destructor, which deallocated the memory allocated by the constructor. Currently the destructor is predefined and called '_end()'. This must be the last method, You call.
      PROC main()
        DEF class:PTR TO myclass()  // this is constructor
    
        ... some code ...
    
        class._end()                // this is destructor
      ENDPROC
      

    here is defined an OOP variable called 'class', which points to the 'myclass' object. On the definition is called the constructor, which allocated the needed memory, and at the end of this procedure is called the destructor.

  • Methods:
    Methods are functions, which are written only for the given class (object resp.) There are two special methods, the '_new()' and the '_end()', which are called constructor and destructor. The constructor is called automatically, so You don't have to care about it.

    Every method is called from it's class, and You need to access to the class' items inside the method. For this purpose there is automatically created a variable 'self' which points to the class.
      PROC set(newname,newage,newsex) OF myclass
        StrCopy(name,newname)
        age:=newage
        sex:=newsex
      ENDPROC
    
      PROC print() OF myclass
        PrintF('\s \s is \d years old.\n',IF sex="m" THEN 'mr' ELSE 'mrs',name,age)
      ENDPROC
      

    This is definition of two methods, where the first one setups all the information of the class and the second just prints it to the cli. As You can see, there is 'OF myclass'. This is the keyword, which assigns the procedure to the object and makes from the procedure method and from normal object a class. And in these methods You can see, that You can access the class' items directly like 'age' instead of 'self.age'.

    To call methods use:
      class.set('MarK',24,"m")
      class.print()
      

    And if You will compile the whole proggy, You will get this:
      mr MarK is 24 years old.
      



  • The complete example:
      OBJECT myclass
        name[16]:CHAR,
        age:CHAR,
        sex:CHAR
    
      PROC set(newname,newage,newsex) OF myclass
        StrCopy(name,newname)
        age:=newage
        sex:=newsex
      ENDPROC
    
      PROC print() OF myclass
        PrintF('\s \s is \d years old.\n',IF sex="m" THEN 'mr' ELSE 'mrs',name,age)
      ENDPROC
    
      PROC main()
        DEF class:PTR TO myclass()  // this is constructor
    
        class.set('MarK',24,"m")
        class.print()
    
        class._end()                // this is destructor
      ENDPROC