The latest drop of ForthOS has facilities available for OO programming.
These are all located in the "extensions" vocabulary.
Object subclass: MyClass
Creates a new class, inheriting from Object (the base class)
ivars: int8 field1 int16 field2 int8 dummy endivars
Adds fields to the most recently defined class (using "struct" syntax)
MyClass :method field2! { val self -- }
val self MyClass>field2 w! method;
Defines a method for MyClass... uses the named arguments support (not
really a part of the OO package, but fits nicely) to store the
passed value into a field of an instance
MyClass new constant var1
123 var1 -> field2!
"-> <selector>" invokes a method of the passed object.
Inheritance works, so if you did:
Object :method sayHi { self -- } ." Hello, world." cr method;
var1 -> sayHi
you would indeed see the printed message, inherited by the MyClass object
out of Object's method table.
Andy
Received on 26 Jul 2004 19:17:38 GMT
This archive was generated by hypermail 2.1.8 : Tue Sep 26 2006 - 09:03:05 PDT