Skip to content

Language Guide: Classes

rollynoel edited this page Jun 18, 2013 · 5 revisions

Added by dholton dholton

Here's an example illustrating some of the basics about classes.

Until more documentation is here, for examples of using classes, see the classes-.boo files under tests/testcases/integration/types, as well as super-.boo, abstract-.boo, interfaces-.boo, baseclass-.boo, innerclasses-.boo, fields-.boo, and properties-.boo.

interface IAnimal:
    Name as string:
        get
 
    Legs as int:
        get
 
    def Eat(food)
 
class Dog(IAnimal):
    Name:
        get:
            return "Canine"
 
    Legs:
        get:
            return 4
 
    def Eat(food):
         if food isa IPlant:
                Speak()
 
    def Speak():
         print "bark!"
 
interface IPlant:
    pass
 
class Rice(IPlant):
    pass
 
//////////////////////////
 
d = Dog()
 
print "$(d.Name) has $(d.Legs) legs."
 
r = Rice()
d.Eat(r)
Clone this wiki locally