forked from brombres/Rogue
-
Notifications
You must be signed in to change notification settings - Fork 2
Inline Initializers
AbePralle edited this page May 5, 2015
·
3 revisions
class ClassName( new_property:Type, inherited_property, ... )
: BaseClassName, ... [attributes]
class PointTest
METHODS
method init
local pt1 = Point2D(3,4)
local pt2 = Point3D(5,6,7)
println pt1 # prints (3,4)
println pt2 # prints (5,6,7)
endClass
class Point2D( x:Integer, y:Integer )
METHODS
method to->String
return "($,$)" (x,y)
endClass
class Point3D( x, y, z:Integer ) : Point2D
METHODS
method to->String
return "($,$,$)" (x,y,z)
endClass
Each class definition can have an inline initializer immediately following the class name. The inline initializer lists a mix of inherited property names (without type declarations) and new property names (with type declarations) and implicitly creates an init() method with listed property arguments.
- Additional PROPERTIES and overloaded init() methods can be defined normally.
- There is no way to add additional statements into the implicitly created init() method - you'd have to replace the inline initializer with separate property and method declarations.
- [compound] classes require the inline initializer syntax to specify the properties that compose the compound.