Polymorphic copy: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: add entry) |
(Added Forth (4tH) version) |
||
Line 625: | Line 625: | ||
C |
C |
||
C |
C |
||
=={{header|Forth}}== |
|||
{{works with|4tH|3.62.1}} |
|||
{{trans|Aikido}} |
|||
There are numerous, mutually incompatible object oriented frameworks for Forth. This one works with the FOOS preprocessor extension of [[4tH]]. |
|||
<lang forth>include lib/memcell.4th |
|||
include 4pp/lib/foos.4pp |
|||
( a1 -- a2) |
|||
:token fork dup allocated dup (~~alloc) swap >r swap over r> smove ; |
|||
\ allocate an empty object |
|||
:: T() \ super class T |
|||
class |
|||
method: print \ print message |
|||
method: clone \ clone yourself |
|||
end-class { |
|||
\ implementing methods |
|||
:method { ." class T" cr } ; defines print |
|||
fork defines clone ( -- addr) |
|||
} |
|||
; |
|||
:: S() \ class S |
|||
extends T() \ derived from T |
|||
end-extends { \ print message |
|||
:method { ." class S" cr } ; defines print |
|||
} \ clone yourself |
|||
; |
|||
new T() t \ create a new object t |
|||
new S() s \ create a new object s |
|||
." before copy" cr |
|||
t => print \ use "print" methods |
|||
s => print |
|||
t => clone to tcopy \ cloning t, spawning tcopy |
|||
s => clone to scopy \ cloning s, spawning scopy |
|||
." after copy" cr |
|||
tcopy => print \ use "print" methods |
|||
scopy => print</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Go does not have the terminology of polymorphism, classes, inheritance, derived types, or overriding. |
Go does not have the terminology of polymorphism, classes, inheritance, derived types, or overriding. |