S
Suresh Jeevanandam
Guest
I am exploring OOPs in Skill++.
I want to create a simple Rectangle class with a @reader function to return area and a method which moves the shape by given dx and dy.
Defining the class is easy.
defclass(Rectangle ()
((x1 @initarg x1)
(x2 @initarg x2)
(y1 @initarg y1)
(y2 @initarg y2)
)
I could not find out how to define the reader and method from the User's guide.
I tried adding the reader function as below, but it does not work.
let(()
defmethod( getArea (( self Rectangle ))
(self->x2 - self->x1) * (self->y2 - self->y1)
)
defclass(Rectangle ()
((x1 @initarg x1)
(x2 @initarg x2)
(y1 @initarg y1)
(y2 @initarg y2)
(area @reader getArea))
)
)
I also want to add the method move(dx, dy) which moves the shape (updates all coordinates). What is the best way to do this?
Thanks.,
Suresh
--
I tried posting this first in community.cadence.com but I don't see any button to start a new topic even after logging-in successfully.
I want to create a simple Rectangle class with a @reader function to return area and a method which moves the shape by given dx and dy.
Defining the class is easy.
defclass(Rectangle ()
((x1 @initarg x1)
(x2 @initarg x2)
(y1 @initarg y1)
(y2 @initarg y2)
)
I could not find out how to define the reader and method from the User's guide.
I tried adding the reader function as below, but it does not work.
let(()
defmethod( getArea (( self Rectangle ))
(self->x2 - self->x1) * (self->y2 - self->y1)
)
defclass(Rectangle ()
((x1 @initarg x1)
(x2 @initarg x2)
(y1 @initarg y1)
(y2 @initarg y2)
(area @reader getArea))
)
)
I also want to add the method move(dx, dy) which moves the shape (updates all coordinates). What is the best way to do this?
Thanks.,
Suresh
--
I tried posting this first in community.cadence.com but I don't see any button to start a new topic even after logging-in successfully.