Abstract type: Difference between revisions

Content added Content deleted
Line 1,425: Line 1,425:
To be of a particular property, a list of methods can tagged as required. For instance, in order to be Comparable, a class should implement <=
To be of a particular property, a list of methods can tagged as required. For instance, in order to be Comparable, a class should implement <=


<lang Oforth>Property new: Circular(r)
<lang Oforth>Property new: Spherical(r)
Circular method: radius { @r }
Spherical method: radius { @r }
Circular method: setRadius(r) { r := r }
Spherical method: setRadius(r) { r := r }
Circular method: perimeter { @r 2 * Pi * }
Spherical method: perimeter { @r 2 * Pi * }
Circular method: surface { @r sq Pi * 4 * }
Spherical method: surface { @r sq Pi * 4 * }


Object Class new: Ballon(color)
Object Class new: Ballon(color)
Ballon is: Circular
Ballon is: Spherical
Ballon method: initialize(color, r) { color := color self setRadius(r) }
Ballon method: initialize(color, r) { color := color self setRadius(r) }


Object Class new: Planete(name)
Object Class new: Planete(name)
Planete is: Circular
Planete is: Spherical
Planete method: initialize(n, r) { n := name self setRadius(r) }</lang>
Planete method: initialize(n, r) { n := name self setRadius(r) }</lang>