Version 1 (modified by hopscc, 17 years ago) |
---|
Class Definitions
Classes are declared using the class keyword. It may have any of the usual access modifiers. The Superclass inheritance and Interface conformance are indicated with the inherits and implements keywords.
Interfaces are declared in much the same way except the keyword is interface and method and property bodies are not defined. Interface hierarchies (SuperInterfaces?) can also be specified using inherits
Instance variables are declared within the class using keyword var.
var <variableName> [ as <Type>] [ is <AccessModifiers>] var _<variableName> [as <Type>] var x as String var _y as int var z as int is private
_ prefix - private ( and directly accessable in methods) without prefix - public (by default ) override using is syntax access using .
class variable access modifier shared as in is shared
- how initialize??
Initializer/constructor
properties
accessing baseclass methods
==Example ==
#Interfaces interface Audible def makesNoise as String interface Mateable pro mateName as String interface Breedable inherits Mateable pro childName as String # class declaration - note indentation class Bovidae def diet as String return 'Herbivorous Cud Chewing' def nHooves as String return 'four' class Sheep is public, nonvirtual # public is default anyway inherits Bovidae # Superclass implements Audible, Breedable var _lifeSpan as int is shared # years average # or var lifeSpan as int private shared var _age as int =1 var liveWeight as int is private var _isAlive as bool #shared # _lifespan = 8 def init _age = 1 .liveWeight = 2 _isAlive = true def makesNoise as String return 'Baaaaa' pro mateName as String get return 'Ram' set pass pro childName as String get return 'lamb' set pass def age( byNYears as int) _age += byNYears if _age > _lifeSpan _isAlive = false def gainWgt( wgt as int) .liveWeight += wgt def toString as String is new return 'Sheep:age=[_age], wgt=[.liveWeight], living=[_isAlive]' def main is shared s = Sheep() print 's=[s.toString]' s.age(1)