Abstract type: Difference between revisions

Content deleted Content added
Franck (talk | contribs)
Line 1,551:
 
<lang Oforth>Property new: Spherical(r)
Spherical method: radius { @r };
Spherical method: setRadius(r) { r := r };
Spherical method: perimeter { @r 2 * Pi * };
Spherical method: surface { @r sq Pi * 4 * };
 
Object Class new: Ballon(color)
Ballon is: Spherical
Ballon method: initialize(color, r) { color := color self setRadius(r) };
 
Object Class new: Planete(name)
Planete is: Spherical
Planete method: initialize(n, r) { n := name self setRadius(r) };</lang>
 
Usage :
<lang Oforth>func: testProperty
{
| b p |
Ballon new($red, 0.1) ->b
Line 1,576 ⟶ 1,575:
System.Out "Earth radius is : " << p radius << cr
System.Out "Earth perimeter is : " << p perimeter << cr
System.Out "Earth surface is : " << p surface << cr ;</lang>
}</lang>
 
{{out}}