Jump to content

Polymorphic copy: Difference between revisions

m
→‎{{header|Sidef}}: improved the demonstration
m (Added the Sidef language)
m (→‎{{header|Sidef}}: improved the demonstration)
Line 1,617:
=={{header|Sidef}}==
''Sys.copy()'' makes a deep-copy of any object and returns it to the caller.
<lang ruby>class T(value) {
method namedisplay {
"T"say value;
}
}
 
class S(value) < T {
method namedisplay {
"S"say value;
}
}
 
var obj1 = T.new("T");
var obj2 = S.new("S");
var obj3 = Sys.copy(obj2); # make a copy to obj2
 
obj1.value = "foo"; # change the value of obj1
say Sys.copy(obj1).name; # prints "T"
obj2.value = "bar"; # change the value of obj2
say Sys.copy(obj2).name; # prints "S"</lang>
 
obj1.display; # prints "foo"
obj2.display; # prints "bar"
obj3.display; # prints "S"</lang>
 
=={{header|Slate}}==
2,747

edits

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