Re: Is this good use of Properties?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>
>
>
>

.



Relevant Pages

  • printing bits ... the right way
    ... \param str The array of characters where the resulting string is to ... \param format A custom format string specific to converting ... render an integer type into a binary string. ...
    (comp.lang.c)
  • Re: Reading LAST line from text file without iterating through the file?
    ... ASCII character values are limited to the 0-127 range. ... these days we use the 8th bit for accented characters instead ... Lines are a record format. ... way to represent an ArrayList<String> losslessly in a single String ...
    (comp.lang.java.programmer)
  • Re: Compare Instr() and IndexOf() performance
    ... The largest file is 780 kb, the format of the file is fixed length record ... (17 characters), I am always searching this files on first 10 characters ... but the contents of this file changes every ... If you just calculate the maximum number of string comparisions that may be ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: How many bytes per Italian character?
    ... to format an ANSI string, and yes, there's a possibility that it isn't implemented on CE, ... you went from a discussion about the number of bytes in Italian characters to a ... Remote Registry Editor rather than in Windows CE. ...
    (microsoft.public.vc.mfc)
  • Re: String parsing question
    ... >My task is to convert items in the third format to the first format, ... >in the string, which may or may not have a trailing semicolon. ... While I could count semicolons easily with strchr, ... your characters really are alphanums, ...
    (comp.lang.c)