Re: Tired of 100s of stupid Getter/Setter methods

From: Chris Smith (cdsmith_at_twu.net)
Date: 12/31/03


Date: Wed, 31 Dec 2003 12:57:31 -0700

Joona I Palaste wrote:
> Chris Smith <cdsmith@twu.net> scribbled the following:
> > Of course, in a pinch, the exception-throwing kludge will work; it's
> > integrated into the collections API and even given a fancy name:
> > "optional methods". However, even its light application there is
> > generally acknowledged to be one of the few great failures of that API.
>
> I have to agree. In my Software Design: Java course, a homework problem
> asked me to demonstrate a problem with the Collections framework. My
> answer was "optional methods", which are a design problem.
> In "real" code, I once had to make an abstract class called an
> "ImmutableIterator". It's a java.util.Iterator that makes remove()
> throw an UnsupportedOperationException but leaves the other methods
> as abstract. This is bad OO design, but with java.util.Iterator being
> what it is, how could I have avoided it?

Another real example. Part of what I maintain is a data access
framework for a particular application. Basically, it's a very simple
O/R mapper plus some utility classes. Recently, in response to some
scalability issues from a large customer, I took a method that
previously read objects from a database and populated a java.util.List,
and instead substituted (in some circumstances) my own implementation of
List that maintains a ResultSet and doesn't instantiate the data until
it's requested.

This broke some remote corner of the application. On looking into it,
it turns out that some other developer had ignored the clear
documentation stating that this list should be treated as read-only, and
had instead discovered that the method was returning an ArrayList, and
had modified that list as if it were some private working-space for an
algorithm. I fixed the client code, and added bold tags around the
appropriate warning in the API docs for the data framework... but I
doubt the developer read the documentation before doing so last time,
and I doubt the next developer will read the docs before doing so again.
It would be nice to be able to return an UnmodifiableList that simply
doesn't HAVE those methods.

-- 
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Relevant Pages

  • Re: Interview
    ... When did it become necessary for a developer to not only know the language used inside out, but also the APIs used, the third party tools used, and basically to have done the same job for the last five years. ... There are just parts of the API swing API that I have yet to have needed and those I'm unfamiliar with. ... If the want ads become polluted with a high enough proportion of the ads being useless then the want ads themselves become unusable, because a job seeker will waste stupendous amounts of time and energy responding to 10x, 100x, or however-many-times as many ads as they'd otherwise need to respond to before getting a bite of some sort. ... the company's market sufficiently. ...
    (comp.lang.java.programmer)
  • Re: About method comments
    ... not used consistly and there is no agreed-upon convention. ... out the API that way. ... perhaps thousands of classes to make the categories consistent will be ... A seasoned Smalltalk developer ...
    (comp.lang.smalltalk)
  • Re: method is not designed for extension
    ... Abstract certainly means "designed for extension", in fact, "required to be extended". ... A developer does know certain things about how people will use their API - all those things that the developer was careful to ensure in the API "contracts", i.e., the method signatures. ... Google "design by contract". ...
    (comp.lang.java.programmer)
  • Re: Interview
    ... It didn't go badly but I wasn't familiar with everything my potential employer did. ... When did it become necessary for a developer to not only know the language used inside out, but also the APIs used, the third party tools used, and basically to have done the same job for the last five years. ... that you could apply what you learned to any language or API. ...
    (comp.lang.java.programmer)
  • Re: Interview
    ... employer did. ... that you could apply what you learned to any language or API. ... Java developer and a damn good swing developer. ... Too little work diversity in a small, ...
    (comp.lang.java.programmer)