Sunday, November 20, 2005

From medium to fine grained...

I'm trying to make the step from medium to fine grained objects.

1) Try to create an object with everything it needs at constructor time.
2) Try to have at most one public method to do the work in the class.
3) All other methods are simply for inspecting the state of the object.

I shouldn't have to call a setter on an object once I've built it. Otherwise I've introduced coupling.

2 Comments:

Blogger Nested said...

I am concerned this might be overzealous, or I may not understand what you're writing properly. From Beck's Smalltalk Best Practices And Patterns: "A large family of classes with only a single method each is unlikely to be valuable." (p.69)

Based on Kent's writing, it appears he advocates classes with clear interfaces (which he calls protocols if I am reading correctly) and responsibilities that don't get confusing, but I don't think he would advocate a bunch of classes, each with just one public method...

1:27 p.m.  
Anonymous Anonymous said...

I like the approach Ted. I've run into a problem (likely from the tooling) trying to take the constructor setter approach when building objects exposed through WebServices. The IBM Tooling fails to in it's inspection (Java2WSDL/WSDL2Java) of the exposed class and throws exceptions at the time of creation.

I can think of few things more annoying than the tooling standing in the way of good design.

oh, and hi!

7:46 a.m.  

Post a Comment

<< Home