Jump to content

Abstract type: Difference between revisions

No edit summary
Line 1,413:
type ut = u t
type vt = v t</lang>
 
 
=={{header|Oforth}}==
 
Oforth properties implement abstract types.
 
A class can have only one parent, but multiple properties.
 
Unlike interfaces, properties can include method implementations and attributes (see lang/Comparable.of for instance).
 
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)
Circular method: radius { @r }
Circular method: setRadius(r) { r := r }
Circular method: perimeter { @r 2 * Pi * }
Circular method: surface { @r sq Pi * 4 * }
 
Object Class new: Ballon(color)
Ballon is: Circular
Ballon method: initialize(color, r) { color := color self setRadius(r) }
 
Object Class new: Planete(name)
Planete is: Circular
Planete method: initialize(n, r) { n := name self setRadius(r) }</lang>
 
Usage :
<lang Oforth>func: testProperty
{
| b p |
 
Ballon new($red, 0.1) ->b
System.Out "Ballon radius is : " << b radius << cr
System.Out "Ballon perimeter is : " << b perimeter << cr
System.Out "Ballon surface is : " << b surface << cr
 
Planete new("Earth", 6371000.0) ->p
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>
 
{{out}}
<pre>
Ballon radius is : 0.1
Ballon perimeter is : 0.628318530717959
Ballon surface is : 0.125663706143592
Earth radius is : 6371000
Earth perimeter is : 40030173.5920411
Earth surface is : 510064471909788
</pre>
 
=={{header|ooRexx}}==
1,015

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.