AOP use cases
Jacek Generowicz
jacek.generowicz at cern.ch
Thu Apr 22 12:11:50 EDT 2004
"Daniel Dittmar" <daniel.dittmar at sap.com> writes:
> Jacek Generowicz wrote:
> >>> SEPARATION OF CONCERNS. [snip]
>
> C moved the I/O from the language to a library. This is separation of
> concerns
Not really. By separation of concerns I mean:
Where previously you had to keep two orthogonal goals in mind in a
single chunk of code, you now deal with each goal separately.
Stupid example:
def foo(a):
print "before", a
a.sort()
print "after", a
...
print "before", a
a.reverse()
print "after", a
foo(bar)
In the above you are manually mixing the concern of modifying an
object, with the concern of tracking its changes. In the following you
separate them.
# Worry about the modifications you want to make
def foo(a):
a.sort()
...
a.reverse()
# Worry about tracking changes to an object
class mutation_reporter:
def __init__(self, obj):
self.obj = obj
def __getattr__(self, name):
if name in mutating_methods:
print "before", self
self.blah(name)
print "after", self
def __setattr__(...):
...
# Weave together the separate concerns.
foo(mutation_reporter(bar))
Is this AOP? Should I care?
Is it useful? Should I care?
(I guess the way one answers questions 2 and 4, is ... err
... interesting.)
More information about the Python-list
mailing list