[Tutor] python varying mulitple inheritance
Alan Gauld
alan.gauld at btinternet.com
Tue Jun 19 09:38:55 CEST 2012
On 19/06/12 06:14, kendy at kendy.org wrote:
> Hmmm. No need to write the whole thing written out. Just how not to code:
>
> class Pocket1(Wallet, Keys, Comb, Usb, CellPhone, WorkBadge):
> class Pocket2(Wallet, Keys, Comb, Usb, CellPhone):
> class Pocket3(Wallet, Keys, Comb, Usb, WorkBadge):
> class Pocket4(Wallet, Keys, Comb, Usb):
> class Pocket5(Wallet, Keys, Comb, CellPhone, WorkBadge):
> class Pocket6(Wallet, Keys, Comb, CellPhone):
> ...
Back to basics. a class is a definition of a *type* of thing, not a
particular case. A Pocket is a general purpose container. Each instance
can hold many things. So you would normally expect one pocket class and
6 instances. Each instance holding a different list of items.
The only time you need a different Pocket class is where the pocket has
different *behaviour*. It is normally the behaviours that differentiate
classes not the data. The class data is there to support the class
behaviour. The behaviour of a Pocket is probably some thing like:
addItem
removeItem
findItem
countItems
open
close
empty
In most implementations a Pocket will look a lot like a list...
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list