Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Methods must be defined in classes. They are declared just like functions are.

Code Block
borderStylesolid
titlearguments example
borderStylesolid
class Cat:
    def Roar():
        print "Meow!"

cat = Cat()
cat.Roar()
No Format
bgColor#D8DDE9
titleOutput
borderStylesolid
titleOutput
Meow!

An object of Cat must be instanced, then its methods can be called.

...

Both are optional.

Code Block
borderStylesolid
titlearguments example
borderStylesolid
class Cat:
    def constructor():
        _name = 'Whiskers'

    def destructor():
        print "$_name is no more... RIP"

    [Getter(Name)]
    _name as string

cat = Cat()
print cat.Name
No Format
bgColor#D8DDE9
titleOutput
borderStylesolid
titleOutput
Whiskers
Whiskers is no more... RIP

If a constructor has arguments, then they must be supplied when instancing. Destructors cannot have arguments.

Code Block
borderStylesolid
titlearguments example
borderStylesolid
class Cat:
    def constructor(name as string):
        _name = name

    [Getter(Name)]
    _name as string

cat = Cat("Buttons")
print cat.Name
No Format
bgColor#D8DDE9
titleOutput
borderStylesolid
titleOutput
Buttons
Note
titleBe Careful

Do not depend on the destructor to always be called.

...

All these modifiers also apply to properties (If they are explicitly declared).
static can also apply to fields.

Code Block
borderStylesolid
titlestatic example
borderStylesolid
class Animal:
    def constructor():
        _currentId += 1
        _id = _currentId

    [Getter(Id)]
    _id as int

    static _currentId = 0

...

All the methods defined in an interface are automatically declared abstract.
Abstract methods in a class must have a blank code block in its declaration.

Code Block
borderStylesolid
titleabstract example
borderStylesolid
class Feline:
    abstract def Eat():
        pass

interface IFeline:
    def Eat()

...

One very nice feature that boo offers is being able to declare the values of properties while they are being instanced.

Code Block
borderStylesolid
titleabstract example
borderStylesolid
class Box:
    def constructor():
        pass

    [Property(Value)]
    _value as object

box = Box(Value: 42)
print box.Value
No Format
bgColor#D8DDE9
titleOutput
borderStylesolid
titleOutput
42

The constructor didn't take any arguments, yet the Value: 42 bit declared Value to be 42, all in a tighly compact, but highly readable space.

...