A Techno Blog, mainly about Java

Hollywood Principle

The object that needs to be implemented does not need to instantiate the dependent objects and can rely on the assembler to do the job

The assembler will gather and instantiate, if necessary, all the dependent objects and make them available to the implemented object.

The assembler gathers the required classes through configuration files so a change in the assembler only needs changes to the configuration file.

An example of an assembler is the Spring Framework.

Template Method design patterns (GoF) – Centralization of workflow logic into an abstract superclass. Framework code in the superclass invoke user code.

Problem: Know the steps of an algorithim and the order of the steps, but dont know how to perform all the steps.

Solution: Encapsulate the individual steps we dont know how to perform as abstract methods, and provide an abstarct superclass that invokes them in the correct order. Concrete subclasses of this abstract superclass implement the abstarct methods to perform the individual steps.

[IoC Struts]


December 18, 2004 Posted by | IoC | Leave a comment

Exception Fever

Exceptions Best Practices

Checked :  Java introduced availability of this kind of exception (java.lang.Exception). This type of excpetion represents useful information about the operation of a legally specified request that the caller may have had no control over and that the caller needs to be informed about [problems] [Challenges with Checked Exceptions ]With checked exceptions, Java language forces us to document all the anticipated ways in which control might exit a method:

  1. Java classes must declare any checked exceptions they throw in the method signature
  2. any method that calls a method that throws a checked exception of type E must either catch E or must also be declared to throw E

Unchecked : runtime exceptions (java.lang.RuntimeException). These are exceptions that occur as a result of programming errors or that the program could not be expected to catch (dereferencing a null pointer, falling off the end of an array, dividing by zero, and so on).

Recently, several well-regarded experts, including Bruce Eckel and Rod Johnson, have publicly stated checked exceptions have become a significant source of problems for many large projects.

December 18, 2004 Posted by | J2EE | 4 Comments