Jon and others,
I dunno the audience here very well, but ofcourse I was not talking
about using public members instead of accessors. For every solution
( don't use accessors) there seems to be a problem( then use public
members

) I guess.
The fact that none of the people in reaction understood the basic
pattern of encapsulation very well is bothering me bigtime..
O well lets just assume language problems..
For the record: encapsulation is not considered the same as using
private members and making them accessable again afterwards.
Thats just a style kind of thing, which in fact has no value or deed.
Its just another indirection and thats exactly why OO is a problem
for starters. Bad OO is worse then good procedural programming.
Back to the ground rule that accessors is bad news...
Lets examplify ?
Lets assume we have observation's( yes I am talking a
object-class

), and we have decision's( another one of those).
Some kind of model like: D = [w * O]*
Decisions are losely based upon Observation, one or more if you like
which have some weight(w) too. Lets say we want an application which
simulates the results of my decisions if I change weights to
observation's.
For calculating your decisions you have quit a few options where to
put weight.
One option might be to give Observation a weight and value accessor
and let Decision have an ObservationList where it asks every
Observation for its weight and value and accumalates.
What is the problem of that approach ?
Observation does nothing. Its a meaningless object. Its a bag where
you throw values at which later on you extract them. In my view if you
have a solution like this your Observation class should be removed
from the scene.
A second option might be to give Observation a method CalculateResult
in which it internally multiplies weight * value. Much better if we do
this because we want to remove accessors. So lets remove those. Life
of Observations is getting more meaningfull. Its getting constructed
from Value and Weight and Calculates its own Result.
*problems*
But wait we wanted to build a simulation, so we want possibilities to
change weights. Can you feel the tendency to keep the Weight Accessor?
Still your mentor told you not to use accessors and you are getting
the hang of it. If you have a weight accessor what kind of observation
do we have then ? Its literally a meaningless value in our system.
So at this moment you are caught in a sweat box.
Now design starts.
You have observations to which you want to give weight in simulations.
What are other options besides weight accessor in Observation ?
1) Lets consider creating a simulation class.
2) Lets consider creating observations for every new weight. Within
the context of our simulation the concept of observation might really
be some weighted one..( here design enforces domain modelling)
3) Lets consider to give observation the added responsibility to add
itself to some decisions with some value, maybe dependent upon which
simulation you run...
4) Good Questions arise( here design enforces analysis): what
determins the simulations we want to run ? Does the weight domain
is dependent upon the Observation( Type ), or upon the Decision, upon
both or just user choice and not dependent upon Observation nor
Decision.
5) etc..etc..
I am very sorry that I dont have time or guts to fully explain or
examplify, but I hope you can see the ground rule that Accessor =
AntiPattern can be very strong and short. If you publish more then
50% of your class members in properties consider strongly to remove
the class altogether,or factor out those published properties since
this way the class probably is too dumb..or has an ambigui character.
Rick