I'm working on homework for my object-oriented design class, and I'm having problems with Scala companion objects. I read in several places that companion objects should have access to their own class methods of a companion class, but I can't get it to work. (As a note, the meat of the assignment was related to the implementation of the binary search tree, so I'm not just asking for answers ...)
I have an object that should instantiate my private class, BstAtlas (Bst is also defined in the Atlas object, pulled it out for clarity):
object Atlas { def focusRoom(newRoom:Room,a:Atlas):Atlas = a.helpFocusRoom(newRoom); abstract class Atlas { ... protected def helpFocusRoom(n:Room):Atlas; ... } private class BstAtlas(bst:Bst) extends Atlas { ... protected def helpFocusRoom(newRoom:Room):Atlas = ...
But when I go to compilation, I get the following error:
Question23.scala: 15: error: helpFocusRoom method is not available in Atlas.Atlas a.helpFocusRoom (newRoom);
The helpFocusRoom function must be hidden, but I donβt know how to hide it and still have access to it inside the companion object.
Can someone tell me what I'm doing wrong here?
oop scala
Shaun
source share