Try this:
# constructor for Square
makeSquare <- function(name, side) structure(list(name = name, side =
side), class = c("Square", "Shape"))
# generic
getName <- function(shape) UseMethod("getName")
# Shape method
getName.Shape <- function(shape) shape$name
# generic
getArea <- function(shape)
Coming from a C++ and C# background I would like to know how inheritance works
with 'R'. The classical example is I can define an abstract class 'Shape' and
have an array of 'Shape's but each instance could be a Circle, Square,
Triangle, etc. because they all derive from 'Shape'. At runtime if I
2 matches
Mail list logo