benefits of using self type annotations over inheritance

> In composition I can be of *any* type, as long as I implement some
methods you want from me

I dont get it:

Here is a composition:

scala> class Orange(gardener: Gardener)
defined class Orange

it will accept only Gardener or subclasses of Gardener and not "any object
which implements some methods" we wish for wouldn't it?

On Tue Dec 23 2014 at 8:11:48 PM Konrad Malawski <notifications@github.com>
wrote:

> In sections/self_type.adoc
> <https://github.com/ktoso/scala-types-of-types/pull/27#discussion-diff-22226708>
> :
>
> >  **Self Types** are used in order to "require" that, if another class uses this trait,
> >  it should also provide implementation of whatever it is that you're requiring.
> >
> > +But why use `self type` annotations if you can extend functionality with simple inheritance?  To answer that we need to clarify a few points about methods of functionality reuse in scala.
> > +
> > +With scala traits You can reuse functionality in 3 standard ways:
> > +
> > +1. `extends` / `with` - also marks an `is-a` relationship, you inherit from the functionality you need to reuse.
> > +2. `def someOtherObj: OtherObj` - member overriding, someone else will override `someOtherObj` thus provide you with its implementation and you will get its functionality in your trait, so that you can reuse it.
> > +3. `self type` annotations - functionality reuse by **composition** (very similar to constructor arguments dependency injection in classes).
>
> "kind of", but not really IMHO...
> I mean, you still force users to be of a certain type in order to
> implement such trait (to fulfil the self trait) - so it's not really
> composition. In composition I can be of *any* type, as long as I
> implement some methods you want from me. This is not the case with self
> types - the type must match
>
> --
> Reply to this email directly or view it on GitHub
> <https://github.com/ktoso/scala-types-of-types/pull/27/files#r22226708>.
>