object inheritance
Pradeep Jindal
praddyjindal at gmail.com
Sat Oct 27 16:16:15 EDT 2007
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.
More information about the Python-list
mailing list