##use lists to get oo by contract ##by using class(ttt) <- "point" ##in the correct manner you can easily get S3 classes. plotxy <- function(x, col, xlim, ylim, ...) { xval <- Xpos(x) yval <- Ypos(x) plot(xval,yval, xlim=c(0,xval+1), ylim=c(0,yval+1), ...) } newXY.xy <- function(x,y) list(x=x,y=y) newXY.rt <- function(r, theta) list(x=r*cos(theta), y=r*sign(theta)) newRT.xy <- function(x,y) list(r=sqrt(x^2+y^2), theta=tan(y/x)) newRT.rt <- function(r, theta) list(r=r, theta=theta) pt1 <- newXY.xy(1,2) pt2 <- newRT.rt(4, .44) ##access via functions: Xpos.xy <- function(pt) pt$x Ypos.xy <- function(pt) pt$y Xpos.rt <- function(pt) pt$r*cos(pt$theta) Ypos.rt <- function(pt) pt$r*sin(pt$theta) Rval.rt <- function(pt) pt$r Tval.rt <- function(pt) pt$theta Rval.xy <- function(pt) sqrt(pt$x^2+pt$y^2) Tval.rt <- function(pt) tan(y/x) ##first suppose we are using xy points ##then Xpos and Ypos would have the following defs Xpos <- Xpos.xy Ypos <- Ypos.xy plotxy(pt1) ##suppose instead we were using r-theta ##then we would have defined Xpos and Ypos as Xpos <- Xpos.rt Ypos <- Ypos.rt plotxy(pt2) ##Notice that I did not need to change any code in plotxy