On 04/08/10 18:20, Bruno Desthuilliers wrote: > Lie Ryan a écrit : >> On 04/07/10 18:34, Bruno Desthuilliers wrote: >>> Lie Ryan a écrit : >>> (snip) >>> >>>> Since in function in python is a first-class object, you can instead do >>>> something like: >>>> >>>> def process(document): >>>> # note: document should encapsulate its own logic >>>> document.do_one_thing() >>> Obvious case of encapsulation abuse here. Should a file object >>> encapsulate all the csv parsing logic ? (and the html parsing, xml >>> parsing, image manipulation etc...) ? Should a "model" object >>> encapsulate the presentation logic ? I could go on for hours here... >> >> Yes, but no; you're taking it out of context. Is {csv|html|xml|image} >> parsing logic a document's logic? Is presentation a document's logic? If >> they're not, then they do not belong in document. > > Is len() a list logic ? If yes, it should belong to list !-)
Yes, that's why list.__len__() belongs to list while len() is a convenience function that doesn't carry any concrete implementation. > There are two points here : the first is that we (that is, at least, you > and me) just don't know enough about the OP's project to tell whether > something should belong to the document or not. period. I think I see your point here. I retract my suggestion that it is suitable for OP's purpose since I just realized OP is in a better position to make the decision. > The second point > is that objects don't live in a splendid isolation, and it's perfectly > ok to have code outside an object's method working on the object. > wrt/ these two points, your "document should encapsulate its own logic" > note seems a bit dogmatic (and not necessarily right) to me - hence my > answer. I agree with you about there are certain logics that should not be inside the object (that's why I qualify the statement with `should`). Glue logic, by definition, cannot be inside an object. I don't think we are actually in disagreement here. But I think the dogma, followed with caution, is generally good. -- http://mail.python.org/mailman/listinfo/python-list