lessons

2006-12-14T15:10:03Z
Dave Pawson.  link
Home

Lessons learned

Lessons learned

I've converted a number of classes to Singletons over the last week and learned a few lessons along the way. Firstly that Singletons need thought. That they are infectious, or more exactly impact other objects that they use. Finally, that they aren't a single solution. The latter is probably the biggest lesson. I'm using a factory pattern in my braille engine to select the translator to use, based on the value of xml:lang. The translator is locale specific hence care needs to be taken that locale A doesn't spill over into locale B. This applies when formatting translated braille. The simple point is that the braille table, which includes code as well as data, is needed at various points in the application. I had been passing the braille table around as a parameter to the class constructors. I realised that in some cases this is grossly inefficient. Hence the move to singletons. Do it once and re-use it. Except that darned factory pattern keeps getting in the way. Simplistically I need the language string to be kept handy, and used to pick the appropriate braille table. That seemed all wrong, so I'm currently straddling the two solutions with an itch! Singleton in use and still passing the table as a parameter to some objects. The other classes which presented obvious candidates were easier. The Error Handler is used for debug logging and sax parse errors. That worked out fine. Similarly the properties file was an ideal match, lets any class go get property. Nearly fell into the trap spreading property names left right and centre over the application, then loose coupling stepped up and hit me, so I'm defining the property names in the class that gets them as static final Strings.

All in all, I'm learning quite a lot. And enjoying it, which is good.

Professional Web 2.0 Programming

Listening to Eric on his blog, I was tempted and bought the book Which seemed like a good idea at the time. The early reading indicated we weren't going to be introduced gradually to each of the technologies, which seemed acceptable. Then they hit us with the first example. Load this PHP file into Apache... Oh yes.

I wonder how many people have simply stopped at that point and dropped the book? Configuring Apache for PHP, loading the files into the right place etc etc etc. The other view is, dear reader, jump this high hurdle. I'm surprised a reviewer didn't pick that one up. It's gone back on the reading list, far back.

Keywords: java

Comments (View)

Return to main index