Is there a way to access the parent through the child object?
For example, imagine a simple game where by if a ball is in a certain position
(eg the goal) a goal is scored and the score for that game is updated.
Imagine also that the score is dependent on the size of the ball.
So a ball of size 3 gives you 3 points.
A ball of size 8 gives you 8 points etc.
Each game object has a ball object.
Code: Select all
(defclass game () (score :initform 0 :accessor game-score) (game-ball :initform (make-instance 'ball))) (defclass ball () (size :initform 1 :accessor ball-size)) (defmethod move-ball (ball x y) (if (ball-is-in-goal-p x y) <update-score> (move-ball-as-normal)))
I realize there are various things I could do
like make the ball a global variable or make the move-ball method accept
a game object. However is there something equivalent to