object inheritance

Anand anandology at gmail.com
Wed Oct 31 04:26:26 CET 2007


On Oct 28, 1:16 am, Pradeep Jindal <praddyjin... at gmail.com> wrote:
> On Friday 26 Oct 2007 6:21:57 pm Anand wrote:
>
>
>
> > On Oct 26, 5:31 pm, "Pradeep Jindal" <praddyjin... at gmail.com> wrote:
> > > Can you tell any specific use case for doing this?
>
> > I have many implementaions of a db interface.
>
> > SimpleDB - simple implementation
> > BetterDB - optimized implementation
> > CachedDB - an implementation with caching of queries
> > RestrictedDB - implementation with permissions
>
> > Now, I want to combine these implementations and use.
> > Typical use case scenarios are:
>
> > db = RestrictedDB(CachedDB(SimpleDB()))
> > db = RestrictedDB(SimpleDB())
> > db = RestrictedDB(BetterDB())
> > db = RestrictedDB(CachedDB(BetterDB())
> > db = CachedDB(SimpleDB())
> > etc..
>
> I agree with Duncan. According to me, this should be called Delegation rather
> than inheritance. And delegation should work without any conflicts of
> identifier names and all that. I think, it should be all about several
> objects implementing a protocol (interface) and that should work cleanly.

I don't think so. It is not as simple as delegation.

In the example that I gave previously, call to self.say in A.foo
calls B.say not A.say, which I think is not possible with delegation.







More information about the Python-list mailing list