Re: [Modeling-users] specifying objects' class
Status: Abandoned
Brought to you by:
sbigaret
|
From: John L. <jo...@vi...> - 2004-02-10 21:08:35
|
On Tue, Feb 10, 2004 at 04:57:02PM -0300, John Lenton wrote:
>=20
> hmm... it isn't clear to me that this is always what you want;
> currently we're using (in an unrelated field) a linearization of that
> graph into
>=20
> Employee <| Person <| EmployeeBase <| PersonBase
>=20
> although I can see that in this case you are (on first sight at least)
> correct. However, no matter what is expected, it is exactly what the
> C3 MRO in python 2.3 does. If you want your behaviour, all you have to
> do is declare Employee as
>=20
> class Employee(EmployeeBase, Person)
>=20
> whereas if you want the other behaviour you declare it as
>=20
> class Employee(Person, EmployeeBase)
after discussing it with Federico (Heinz) I realized I wasn't being
particularly clear on this point, so, at risk of boring you all to
death over a subject you care little about, I'll expand on this a bit.
First, Federico understood that S=E9bastien is suggesting that the
EmployeeBase class must explicitely inherit from Person, which is
seems odd to me; could you (S=E9bastien) clarify that? What I understood
you to mean was that the EmployeeBase MRO was as you described. As one
would never instanciate *Base objects, all is well.
and now for something completely the same:
class PersonBase(object):
pass
class EmployeeBase(PersonBase):
pass
class Person(PersonBase):
pass
class Employee(EmployeeBase, Person):
pass
print ' Person MRO:', [i.__name__ for i in Person.mro() ]
print ' Employee MRO:', [i.__name__ for i in Employee.mro() ]
class Employee(Person, EmployeeBase):
pass
print 'Alt. Employee MRO:', [i.__name__ for i in Employee.mro() ]
just to be clear, IMHO the first way is the right way to do it if you
know the subclasses will never want to override the superclass. This
is the case of concrete classes in a templated abstract factory, for
example. The second way is probably what you want most other times.
In both cases all bets are off if you ever instanciate a *Base.
Clearer?
--=20
John Lenton (jo...@vi...) -- Random fortune:
Is that really YOU that is reading this?
|