Re: [Modeling-users] specifying objects' class
Status: Abandoned
Brought to you by:
sbigaret
From: John L. <jo...@vi...> - 2004-02-10 19:58:01
|
On Tue, Feb 10, 2004 at 04:28:22PM +0100, Sebastien Bigaret wrote: > > That's the reason why the -B switch exists in the script > mdl_generate_python_code.py ;) Oops, I didn realize that was what it was for :-/ > A little remark: this is a little different than just inheriting from > the mdl-generated class: when inheritance comes in, e.g. for Employee > deriving from Person, you don't want to have: > > Employee <|-- EmployeeBase > ^ > /_\ > | > | > Person <|-- PersonBase. > > rather you want: > > Employee <|-- EmployeeBase <|-- Person <|-- PersonBase > > so that Employee inherits from the business-logic defined in Person, > as expected. 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 Employee <| Person <| EmployeeBase <| PersonBase 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 class Employee(EmployeeBase, Person) whereas if you want the other behaviour you declare it as class Employee(Person, EmployeeBase) unfortunately this only applies to new style classes as of python 2.3; I'm not certain the (hackish) MRO in 2.2 DWIMs. > Shortly said, this means no code-generation, with the ability to just > define your business logic, with the mdl-specific stuff automatically > generated at runtime (you'll want to use the metaclass approach > then). Additionally, new-style classes makes things run quicker ;) > Note that while this is not integrated into the main trunk yet, this > will shortly be. In fact, it should already be there, if only I have > had the time for it... new-style classes would be nice for several reasons, not only performance. For starters, the fact that you can query the MRO and use super(), makes multiple inheritance manageable. By the way, did you compare the speed of your metaclass approach to an exec? -- John Lenton (jo...@vi...) -- Random fortune: The early worm gets the late bird. |