Classes

A class for this, a class for that.

Classes are the lifeblood of object-oriented programming. Caboose has full support for classes and objects!

Defining a Class

Classes provide the basis for object creation in Caboose

example_class_definition.cb
class SomeClass {
// Constructor
init() {
println("Object created!");
}
}
SomeClass(); // Prints "Object created!"

Constructor

init() is the name for a constructor in Caboose. A constructor is a method that is called when an object is instantiated. Instantiating an object is just like invoking a function, except you “invoke” the class. You can also pass arguments to the constructor to be used.

example_class_constructor.cb
class SomeClass {
// Constructor
init(message) {
println(message);
}
}
SomeClass("Object created!"); // Prints "Object created!"