I am teaching Scala for the first time and my students are finding the deliberate "punning" involved in companion objects very confusing. Consider the following example:
class Stack {
... methods such as push/pop
}
object Stack {
... factory method(s) and possibly others
}
The confusion comes in when I use verbal phrases such as "a stack object" or "stack objects" or especially "the stack object". My students have difficulty understanding whether I mean the singleton object Stack or objects of the Stack class.
I'm looking for alternative ways to verbalize such things that beginners can understand more easily. I've considered always referring to objects of the Stack class as "Stack instances" or "instances of Stack", but it seems crazy when trying to teach OO not to be able to call these things objects. I've been trying to ALWAYS use the phrase "singleton object" or "companion object" when talking about the singleton object Stack, but the syntax of Scala is working against me there because it only uses the word "object".
In this case, I could rename the singleton object StackFactory instead of Stack, but that's only an option for my own classes, not for the thousand and one companion objects already built into Scala.
Edit:
Sorry, I wasn't clear enough in my question. The main confusion happens NOT when referring to the companion object. In that case, as several people have noted, it is easy enough to use to a phrase such as "the companion object". Instead, the main confusion happens when referring to ordinary instances. Then, if I say "a stack object" (meaning some stack instance) or "the stack object" (meaning this particular instance), some fraction of the students will think I mean the companion object -- even though I did not use the word companion or singleton.
And I can see perfectly well where the confusion comes from, because the word "object" appears in the program text only with the companion object.
Stack
) companion"? – Heidi