Pass the Dictionary, Please

beno zope at thewebsons.com
Mon Dec 9 14:39:18 EST 2002


At 11:42 AM 12/9/2002 -0800, you wrote:
>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.

Would you mind helping me clarify what you just said by means of an example?

ClientData() has method
assembleGatewayData(paymentVehicle : int, **customerCreditInfo: dict, 
**gatewayData: dict)
which it calls upon itself.

ClientData() has method
assembledDataPackageToGetCreditApproval(**sendToGateway : dict)
which it calls upon Object Payment.

Payment() has method
startProcessToGetCreditApproval(**sendToGateway : dict)
which it calls upon Credit()

Credit() has method
startGatewayContactToGetCreditApproval(**sendToGateway : dict)
which it calls upon ConnectToBank_html()

How would you tighten this up and stick to the Law of Demeter?
TIA,
beno






More information about the Python-list mailing list