in reply to Re^17: Assignable Subroutines
in thread Assignable Subroutines
I don't understand what you mean by "higher up".It's in the caller in your code too, it's just all stuffed into an effect object which is created and applied by the caller and I still haven't seen an example of why that might cause a problem.I mean the code to handle this is lifted outside the class and into the caller.
I, for one, like the addition of small, domain specific languages. Your choice is to either learn an API or learn a (small) language. Choosing one or the other tends to force you twards different design decisions, but the cost of learning is not so different.Yes they're great but I have 2 problems with your.
withmy $effect = Effect->new( [ salary => 1.02, '*' ], [ frobnitz => 1.5, '+' ], ); $_->apply_effect( $effect ) for @employees;
which may not look so different but because it's actual Perl it requires no learning at all. It also would allow stuff likemy $effect = Effect->new; $effect->salary *= 1.02; $effect->frobnitz += 1.5; $_->apply_effect( $effect ) for @employees;
$effect->salary = $effect->frobnitz + 1.5;
Encapsulation is hiding data and behavior. Applying trvial mutators exposes data. It's therefore bad encapsulation. QED.
That's exactly the circular logic I was talking about. Your using your own definition of encapsulation to to justify itself. You've basically said "it's not my kind of encapsulation therefore it's bad encapsulation".
For me, encapsulation does not mean hiding all data it just means hiding particular pieces of data from particular parts of the program. In many situations, some data really does need to be exposed but by exposing the data through methods you are not breaking encapsulation because the actual internal data is still guarded from direct manipulation.
You keep talking about trivial mutators. Are non-trivial ones OK? If so what should I do if I change my implementation so that a non-trivial mutator is now trivial?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^19: Assignable Subroutines
by hardburn (Abbot) on Jan 27, 2005 at 22:30 UTC | |
by fergal (Chaplain) on Jan 27, 2005 at 23:32 UTC |