Hello World ooREXX

Ok, as my previous post showed how to write a routine oriented hello world program in gforth, I now explain a hello world program using objects in object oriented rexx (ooRexx).

    Object Oriented Hello World in REXX

myobject = .hello~new

::class hello
 ::method init
 expose hellostring
    hellostring = "Hello World"
 ::method print
 expose hellostring
    say hellostring

Like all rexx programs, the main() like section is the beginning lines of the program. The object definitions begin after the main instruction sequence. In this case we have one object called “hello”

::class hello

It contains two methods, a constructor and general purpose method named “print”. Both objects share a variable common to the object called “hellostring”, which contains the string we want the object to print. It is initially set by the constructor to the value “Hello World”. The print method does only one thing, to print the value of the variable “hellostring” to the console.

So, here we have an illustration of using objects, methods, constructors and internal data passing between objects in a rexx program. (Note, I am not going into the details of what is object oriented programming, as if you reading this you should have already studied what is object oriented programming).

The beginning part of the program does two things, create an object named “myobject” of the type “hello” and initialize it. The second instruction calls the “print” method.

Pretty simple.