The original question is 12 years old at the moment, now Scala is mature enough to have simple (much more simpler compared to other languages) answers to such requirements. Back to the original question, objects (more accurately singleton objects) are like values it's not meaningful to extend them, types are meant to support such scenarios. In Scala we have classes and traits for extension purposes so your wording should have been (i.e. extensibles should be declared as traits):
trait X
object Y extends X
On the other hand extension methods can be used to extend an object. Suppose we have:
object X:
def oldMethod: Unit = ()
object Y
The following adds a new capability to Y
based on old implementations from X
(note that we should use the singleton type (Y.type
) as the type of y
, because Y
itself is not a type but a specific and the only instance of that type):
extension (y: Y.type) def newMethod: Unit = X.oldMethod
Now the following successfully compiles:
Y.newMethod
To clarify, the original question is somehow ambiguous because it does not distinguish between values and types.