lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tuesday 18 January 2005 07:09, Chris Pressey wrote:
> And since most peoples' idea of OO seems to have both encapsulation and
> inheritance in it, well, it looks like there's an inevitable tradeoff.
>From another perspective there's not so much of a tradeoff ...

> not very forward-looking.  Future programmers might have very original
> ideas for how to extend these classes I'm designing that I haven't even
> considered, so I probably shouldn't make them unduly difficult to
> extend.
... since IMHO extending is not really made ``easy´´ by just exposing
everything. It may be more convenient, but then there's still usually
some contract attached to the exposed state. Not adhering to it will
byte extension programmers in weird ways, and usually they will be
tied to one version of your base class.

If on the other hand you go all the tiresome way of providing appropriate
methods in your base class to even access the ``second level interface´´
in a safe way, i.e. you code that not-so-public contract, writing extensions
will be easier and in that sense there is optimal inheritance, too.

You still may be using some means of packaging, including closures,
or just some linter, to control which code has access to these methods,
but this need not necessarily be the derived classes. For example sometimes
one wants to implement an is-a relation by means of a has-a relation
(freely mixing interface inheritance with implementation inheritance).