September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
60
Task/Abstract-type/OoRexx/abstract-type-1.rexx
Normal file
60
Task/Abstract-type/OoRexx/abstract-type-1.rexx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
-- Example showing a class that defines an interface in ooRexx
|
||||
-- shape is the interface class that defines the methods a shape instance
|
||||
-- is expected to implement as abstract methods. Instances of the shape
|
||||
-- class need not directly subclass the interface, but can use multiple
|
||||
-- inheritance to mark itself as implementing the interface.
|
||||
|
||||
r=.rectangle~new(5,2)
|
||||
say r
|
||||
-- check for instance of
|
||||
if r~isa(.shape) then say "a" r~name "is a shape"
|
||||
say "r~area:" r~area
|
||||
say
|
||||
|
||||
c=.circle~new(2)
|
||||
say c
|
||||
-- check for instance of shape works even if inherited
|
||||
if c~isa(.shape) then say "a" c~name "is a shape"
|
||||
say "c~area:" c~area
|
||||
say
|
||||
|
||||
-- a mixin is still a class and can be instantiated. The abstract methods
|
||||
-- will give an error if invoked
|
||||
g=.shape~new
|
||||
say g
|
||||
say g~name
|
||||
say "g~area:" g~area -- invoking abstract method results in a runtime error.
|
||||
|
||||
-- the "MIXINCLASS" tag makes this avaiable for multiple inhertance
|
||||
::class shape MIXINCLASS Object
|
||||
::method area abstract
|
||||
::method name abstract
|
||||
|
||||
-- directly subclassing the the interface
|
||||
::class rectangle subclass shape
|
||||
|
||||
::method init
|
||||
expose length width
|
||||
use strict arg length=0, width=0
|
||||
|
||||
::method area
|
||||
expose length width
|
||||
return length*width
|
||||
|
||||
::method name
|
||||
return "Rectangle"
|
||||
|
||||
-- inherits the shape methods
|
||||
::class circle subclass object inherit shape
|
||||
|
||||
::method init
|
||||
expose radius
|
||||
use strict arg radius=0
|
||||
|
||||
::method area
|
||||
expose radius
|
||||
numeric digits 20
|
||||
return radius*radius*3.14159265358979323846
|
||||
|
||||
::method name
|
||||
return "Circle"
|
||||
51
Task/Abstract-type/OoRexx/abstract-type-2.rexx
Normal file
51
Task/Abstract-type/OoRexx/abstract-type-2.rexx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
-- Example showing an abstract type in ooRexx
|
||||
-- shape is the abstract class that defines the abstract method area
|
||||
-- which is then implemented by its two subclasses, rectangle and circle
|
||||
-- name is the method inherited by the subclasses.
|
||||
-- author: Rony G. Flatscher, 2012-05-26
|
||||
-- changed/edited: Walter Pachl, 2012-05-28 28
|
||||
-- highlighting: to come
|
||||
|
||||
r=.rectangle~new(5,2)
|
||||
say r
|
||||
say r~name
|
||||
say "r~area:" r~area
|
||||
say
|
||||
|
||||
c=.circle~new(2)
|
||||
say c
|
||||
say c~name
|
||||
say "c~area:" c~area
|
||||
say
|
||||
|
||||
g=.shape~new
|
||||
say g
|
||||
say g~name
|
||||
say "g~area:" g~area -- invoking abstract method results in a runtime error.
|
||||
|
||||
::class shape
|
||||
::method area abstract
|
||||
::method name
|
||||
return "self~class~id:" self~class~id
|
||||
|
||||
|
||||
::class rectangle subclass shape
|
||||
|
||||
::method init
|
||||
expose length width
|
||||
use strict arg length=0, width=0
|
||||
|
||||
::method area
|
||||
expose length width
|
||||
return length*width
|
||||
|
||||
::class circle subclass shape
|
||||
|
||||
::method init
|
||||
expose radius
|
||||
use strict arg radius=0
|
||||
|
||||
::method area
|
||||
expose radius
|
||||
numeric digits 20
|
||||
return radius*radius*3.14159265358979323846
|
||||
Loading…
Add table
Add a link
Reference in a new issue