This page take you through the process of writing a Managed Object from scratch.
Start with the file called src/MyManagedObject.java, it already contains the required import statements, and add your code to the class.
First you must tell the compiler that this is to be a managed object. To do this you must specify that it implements ManagedObject
class MyManagedObject implements ManagedObject {
Now you need a constructor bound to a PonderTalk command so that the Ponder2 factory knows what to call when you want to instantiate your object. This is done by using the Ponder2op annotation
//* Creates an instance of this object
*/
@Ponder2op("create")
public MyManagedObject() {
}
This says that the factory message create must be used to create an instance of this object. You can use any name you like and any number of constructors (with different Ponder2op names) as you like.
//* Creates an instance of this objectThis says that the factory message size: must be used to create an instance of this object with a given size. See below for the use of arguments with PonderTalk.
*/
@Ponder2op("size:")
public MyManagedObject(int startSize) {
}
For each PonderTalk command that you want to use, use must create a method with the appropriate annotation and method arguments. This always takes the form:
@Ponder2op("PonderTalk_command")
public void method(args) {
}
Where PonderTalk_command is the name of the command that PonderTalk translates your code into. The number of method arguments must match the command given.
A Unary command has no arguments and will look like this:
Java | PonderTalk |
@Ponder2op("doit") |
myobj doit. |
A Binary command always has one argument and will look like this:
Java | PonderTalk |
@Ponder2op("+") |
myobj + "Fred". |
Keyword arguments are concatenated together with the ':' character following each keyword. You may have one or more keywords comprising a keyword command. A Keyword command with three keywords will look like this:
Java | PonderTalk |
@Ponder2op("hours:mins:secs:") |
myobj hours: 5 mins: 30 secs: 0. |
NB. Ensure that you have colons when you need then and don't when you don't. Every time you have a colon you need an argument.
If you want a command to return a value other than the object itself, then simply return a value. Currently you can only return Strings, booleans, ints and managed objects. Other simple types and more complex types such as XML will be added later.