Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Object Oriented Programming in Skill++

瀏覽次數:35 次
跳到第一則未讀訊息

Suresh Jeevanandam

未讀,
2017年2月16日 清晨6:38:272017/2/16
收件者:
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.
0 則新訊息