Pass the Dictionary, Please

Dave Brueck dave at pythonapocrypha.com
Mon Dec 9 14:42:06 EST 2002


On Mon, 9 Dec 2002, beno wrote:

> If one follows the Law of Demeter, doesn't it make more sense to pass 
> dictionaries of data instead of containing data in classes that are called?

No, that's no different than using C (structs only, no classes).

For one thing, just passing the data doesn't help at all because both
sides still need to know what data is there and what to do with it (one of
the fundamental "wins" of OO is grouping data and the code that operates
on that data into semi-encapsulated chunks). 

Also, if anything, just passing a dictionary risks producing tighter
coupling since your "interface" between the two pieces of code has been
dumbed down to the level of variable names, so any internal refactoring
affects larger chunks of code.

Finally, the interaction between two pieces of code is rarely limited to 
just tossing data back and forth - that's one of the main reasons methods 
exist - so that you can encapsulate as much as possible the knowledge on 
how the data is stored/manipulated internally.

-Dave





More information about the Python-list mailing list