Class and Members

Shang has full support for object oriented programming. In addition to most of the standard ingredients of OOP, several inovative features including member attribute domain, validator, and conditional class make the class interface cleaner, more expressive, and OOP both safer and more flexible. The following demonstrates how simple classes can be created and how domains are used. For more details refer to the language reference manual.
// create a circle class. Note that a class is, like a function, a value, and
// therefore should be assigned to a variable. So "circle" is not the name of
// the class, but the name of the variable used to store the class
circle = class 
              public radius = (0+ to inf);
              auto   perimeter = () -> 2 * pi * parent.radius;
              auto   area = () -> pi * (parent.radius)^2;
         end
person = class
           public gender = "M" in {"F", "M"};
           public age = 1 in (1 : 150);
           public firstname = "Mark" in ~/[A-Za-z][A-Za-z]*/;
           public lastname = "Brown" in ~/[A-Za-z][A-Za-z]*/;
         end



oz 2009-12-22