B
Brett
Rick Elbers said:Brett,
Either you dont want to understand or you really dont.
None of us here is programming stringclasses, so its NOT a valid key
example.
What I said was that in your applications you dont publish things like
stringlength. Maybe you understand this ?
Then for the generalization: in general properties make publicity to
easy. If you want to know something simply ask some class to tell it
to you.
And how do you expect to ask if all of the answers are hidden? I ask an
object a question. Meaning I access a property. The property has a value.
I guess you call this the answer. What else are you thinking of?
What do you mean by "force of OO"?Thats not making use of the force of OO.
I agree. Why do you believe stringlength is an implementation detail? HowOO shines when
complex behaviors are encapsulated and *not* its implementation
details published.
the object calculates string length is an implementation detail. The result
of it is not...if it is made public. At some point, if you need string
length, you have to ask for it and the object will give it. i.e.
mystring.length. Or do you plan on calculating this this everytime via some
function you've devised?
-One more example about stringlength ?
Lets say we have some compact framework event recorder. Possiblee
events are preconfigured as behaviors and subjects. The configuration
will be done on desktop. Now for the specific stringlength
requirement. It turns out that since we want to score in a datagrid in
a pda behaviors or subject with a name longer then 20 characters is a
problem since they dont fit nicely next to each other on the screen.
On the desktop this is not a problem.
Now how to encapulate this requirement ?
I gave you a few solutions in specific order..
1) Do you want to have an ordinary textbox on a form which asks
Subject for length and performs some truncate if needed ?
* worst solution and will probably use stringlength properties here*
2) Do you want specific inherited textbox's for Subject and Behavior
which knows how to truncate ?
3) Do you want to make Subject and Behavior themselves smart enough to
know how to truncate if needed ?
4) Do you want a new formatter class which to give to Subject and
Behavior to formats its name ?
All of the last three ( and much more of those) allow you to keep the
implementation details with the Subject and Behavior themselves.
I agree. However, at some point you'll need to ask for this length (via
property because I doubt the FLC exposes it as a field) or calculate it.
Maybe I'm still not understanding your point. Sorry if that is the case.
Anyways...gl
Rick
Rick Elbers said:Jon,
On Sun, 15 May 2005 07:58:17 +0100, Jon Skeet [C# MVP]
Ah yes - I seem to remember seeing it before and disagreeing with it
then. The idea that a class should be able to draw itself just in
case
it's needed in a UI seems ridiculous to me - which UI should be
picked,
for instance? SWT? Swing? AWT? All three? What about a web UI? What
happened to separating presentation logic from business logic? How
can
the author of a business class know all the different ways in which
it
may need to be drawn?
We agree! In this kind of cases I rather use bridge pattern which you
only implement IF you need a specific OS/Framework. On the other hand
if you have the choice to make a shape know how to connect to other
shapes and draw itself on device context the shape itself has identity
and is a valid class. If on the otherhand shape is only telling
client-"managers" what it is, can do and how it draws in my view shape
is a property bag which is not a valid class. My choice is to make it
without the managers..
Well, that depends on whether it knows in advance what the managers
will want to do. Again I give the example of String - is that not a
proper class? It only knows about itself and what it consists of. It
allows manipulation (into new strings) and retrieval of the text.
That's all it needs to do.
In other words, it concentrates on its domain (text) and nothing else.
That appeals to me.
Strange concept of domain do you display here. In my view domain is
application domain. String has no application domain, its a framework
class and as such very special. The string class is appealling ever
since stl prototyped the first version thats sure, however its not my
model for domain classes at all. Its an utility kind of class in my
view. It might be that this is the reason for our miscommunication.
It puts the onus on a class to know all the ways in which it might be
used, rather than providing something which can be used in a variety
of
situations.
Interesting statement. Do you think we can formulate a basic tension
in design: encapsulation versus usability ? Class for all users is on
the one hand the absolute monolite, property bag for all users in on
the other hand the absolute dumbo.
No-one has suggested that all classes should expose everything about
their implementation as properties though. No-one's claimed that
properties are the universal solution - we've just claimed that they're
not the anti-pattern you see them as.
I only expose things as properties when I see a need to, but I often
*do* see a need to expose *some* of the state of a class as a property.
That state isn't always a direct mapping with the variables of the
class, of course - it's the logical state of what the class logically
describes. As such, the state is part of the interface of the class
just as much as the methods are.
I can see it working in some situations, but overall I'm
not a fan.
If we talk the context of beginners it might be different from
experienced programmers. Experienced programmers have made some smart
objects, and know the value of encapsulation. Maybe they are on the
risk of goldplating. Beginners on the other hand certainly those from
procedural or database worlds might gain from the challenge to make
smart objects since their risk might be to make goto spaghetti code
with objects in property bags..
So tell people not to expose every variable as a property - tell them
to be selective. I have no problem with that. When you tell them that
properties are anti-patterns with simple statements like "don't use
accessors" you're making far too strong a statement in my view.
Ok. Strong statements sometimes work, sometimes they dont lol
Regards and see u around,
Rick
I still don't see your points Rick. Sorry. Asking a string object for
its
length is no problem. It wouldn't be a method in that class if it were.
Accessors are good and allow you to valide incoming values to set on the
property. Properties allow more levels of encapsulation. I still don't
see
any point for not using them. Although you believe universally they
shouldn't be part of OO. The large number of OO books published will
religiously disagree with you.
What I gather is Rick believes accessors are bad and stings shouldn't
expose
length, of which I have seen him make no valid point for those reasons.
Jon, if you believe Rick has made any valid points, please rephrase them
into your own thoughts. I find his wording difficult to understand. It
would help me to see what exactly he is argueing against.
Any who, thanks.
Brett