Re: Is this good use of Properties?
- From: Rick Elbers <rick.elbers@xxxxxxxxx>
- Date: Sat, 14 May 2005 10:08:40 GMT
On Sat, 14 May 2005 01:54:03 GMT, "Bill Butler" <qwerty@xxxxxxxx>
wrote:
>
>"Rick Elbers" <rick.elbers@xxxxxxxxx> wrote in message
>news:j08a81ti69dkulp755m4ksbelh3mr8knvd@xxxxxxxxxx
>
>I hunted around a bit and came up with this:
>"Why getter and setter methods are evil " by Alan Holub
>http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html
>pay close attention to the forum that follows the article.
>(He does not get unanimous acceptance)
>
>It seems to describe your point (if I understand correctly)
>-----------------------------------
>
>I can firmly agree that loose coupling is a good idea. (but not always)
>I can firmly agree that excessive use of accessors can be bad.
>Never using accessors is just plain stupid.
Ofcourse it is. It is however a very good beginnersadvice.
It will make it necessary for them to think before using
obvious functional desicions like using classes as property bags.
Thats in my view probably the single most used abusive of OO.
>
>******************************************
>By the way.
>You were quite rude in your response to Jon.
>Instead of insults and rhetoric, how about examples
>to back up your claims (In C#)
>You blew off his examples instead of producing the code
Was not ment to be rude. Rather be short, if you take that
for rude I apologize. I believe a lot in being short, even if
the statements are not entiraly correct -good heuristics
never are 100% correct-.
Also I am not any more in the habit of programming for free,
nor in the business of programming as a backing of design-heuristic
statements nor- and thats most important- in the business of
lengthy discusions/arguments. You can try my heuristic in the process
of mentoring if you want, or you don't...suite yourself. If you don't
do mentoring and you are not a beginner yourself then my heuristic
will probably not apply to you.
>******************************************
>
>Questions
>Should Arrays/collections expose a Length/Count property?
Yes.
Should Custom Collections expose them ?
Less sure
Should your domain object which has a collection expose its
Length/ Count ?
Probably not.
>Should strings provide accessors for individual characters?
Sure.
Should your domain object use a string class
Sure
Should your domain object expose characters of its used strings ?
Probably not.
>Assuming some class external to string needed to know it's length How would you get it?
Thats where my heuristic points! You dont get it is my *short(rude) *
answer. Think design Think Encapsulatin and take on the challenge to
make your client encapsulate the needed behavior of the client wanting
to know lengthy string..
Not ment to be stupid ofcourse, ment to put programmer in design frame
of mind.
>
>----------------------
>Simple example
>I read in a string from a file (I don't control the format).
>I need to send it across the pipe to another process (I don't control the format)..
>The other process is expecting it in this format
> NNstring
>where NN is the 2 digit length.
>anything over 99 characters is truncated to 99 characters
> so
>"QWERTY" would be 06QWERTY
>"Happy Birthday" would be 14Happy Birthday
>
>I would do something like this
>
Oke stop there!
You have a kind of file! why would you want to send it anywhere if you
know it can't be processed there ? Make either your file check it
himself, or change put to pull mechanism and let your client tell the
file the format he understands.
Thus: NO CODING before design( *dont mean to be rude*)
>public string CustomFormat(string str)
> {
> if (str.Length > 99)
> str = str.Substring(0, 99);
> return (string.Format("{0:d2}{1}",str.Length, str));
> }
>
>--------------------------------
>Please post C# code showing how you would solve this
>
I gave you much more I think then code.
Rick
>
>
> Thank you
> Bill
>
>
>
>
.
- Follow-Ups:
- Re: Is this good use of Properties?
- From: Bill Butler
- Re: Is this good use of Properties?
- References:
- Re: Is this good use of Properties?
- From: Rick Elbers
- Re: Is this good use of Properties?
- From: Jon Skeet [C# MVP]
- Re: Is this good use of Properties?
- From: Rick Elbers
- Re: Is this good use of Properties?
- From: Jon Skeet [C# MVP]
- Re: Is this good use of Properties?
- From: Rick Elbers
- Re: Is this good use of Properties?
- From: Jon Skeet [C# MVP]
- Re: Is this good use of Properties?
- From: Rick Elbers
- Re: Is this good use of Properties?
- From: Jon Skeet [C# MVP]
- Re: Is this good use of Properties?
- From: Rick Elbers
- Re: Is this good use of Properties?
- From: Bill Butler
- Re: Is this good use of Properties?
- Prev by Date: Re: string manip
- Next by Date: Regular Expressions Help
- Previous by thread: Re: Is this good use of Properties?
- Next by thread: Re: Is this good use of Properties?
- Index(es):
Relevant Pages
|