The trouble with all these articles about systems design is that they
never include examples like that. Just broad statements like "the object
should be responsible for all its actions". (Not quoted from the
article, but it said something like that.)

Back in 2001 when I started out with Java I used to believe that sort of
thing. I had objects in my web application, so I gave them each an
"asHTML" method so they could display themselves as HTML. It wasn't long
(about three days) before I found that I wanted to display the objects
differently on different pages (e.g. detailed customer information on
one page, customer name and number on another page, customer name and
address on a third page, and so on). Now I don't do that. And likewise
if I wanted to send an e-mail to a customer, I wouldn't provide the
Customer object with a "sendEmail" method which did that. I would have
something that knew how to send e-mails and something that extracted the
appropriate customer information and put it into an e-mail.

Perhaps that last example wasn't what Holub was meaning to say. But you
sure couldn't tell it by reading the article. And of course he left
himself a big out by emphasizing that it's up to you to apply his ideas
in the proper way. So all I really got from the article is that you
shouldn't **just** use getters and setters which are a thin veneer over
instance variables. Like, you should have an "inactivate" method for
your Customer rather than calling a bunch of setter methods which
implement the logic for inactivating a customer. But not an "asHTML"
method. There's a line to be drawn and as usual it's not clear where the
line goes.

PC2

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of James Perkins
Sent: February 3, 2009 15:37
To: Java Programming on and around the iSeries / AS400
Subject: Re: Java Accessors Are They Evil?

Well, I am a procedural programmer, so that could by why I'm having
trouble grasping this ;-)

My basic class structure for a customer would look something like this.
A Customer class that represents various information about the customer,
id, address, etc.
A CustomerFactory (maybe bad terminology) an interface that would build
the customer.
A CustomerFactoryImpl that would implement the CustomerFactory interface
and build the customer based on a database file.

How would I access information in the Customer class with no accessors?
If I need to know the customers phone number, wouldn't I have to have an
accessor?

And please let me know if I'm completing insane and making a mockery of
the Java language. It's the only way I'll learn ;-)

James R. Perkins

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.