Good programming practices

design pattern

First call of a method

July 7th, 2011

Sometimes there is need to do another action at first call of a method. Suppose client shouldn’t know about that. It can be done in a standard way, using if/else statement and boolean variable indicating first call of a method.

However, another solution exists. Make a class inheriting a standard command class. In inherits class a chosen method is overwritten and has a code that should be executed at first time. At the end of this method a command object is replaced by standard one.
More…

Control flow with String

December 27th, 2010

Motivation

Some programs are controlled by short commands in text form. They may come from user, to be read from a file, or received from another program. This make communication with such a program easier and clearer for other programs. This is a special and simplified case of Interpreter design pattern.

Applications

  • Programs, which gets parameters from the command line.
  • Servlets, for which data are sent using GET or POST.
  • Applets on web pages where the parameters are placed in HTML.

For performance reasons, it is better when there will be interpreted many groups of parameters in a single code run. More…