Tutorials : Putting Design Principles to the Test(A Java based Case Study) :

Designing the RequestHandler

So our initial class diagram for RequestHandler might look like something in Figure 2.

Figure 2: The class diagram for handling the client request

At this point it is clear that the client makes a HTTP call to the ReporterServlet requesting to produce a report. In other situations, a Client can interact with the ReportWriter component using some other protocols such as RMI etc. We will see later in the series how to best accommodate such scenarios. But whatever be the protocol, the RequestHandler component will ultimately make use of the ReportWriter component to produce the report.

Designing the ReportWriter

Now we come to the main bit of the application i.e. designing the ReportWriter component. The following points are important to note:

  • The format of reports can vary from client to client. For example, one client may request an HTML report while another may be looking for an Excel based report.
  • To produce each individual report format, we might need to implement different technologies. For example, while HTML formatted reports are easy to produce; Excel reports may be little more complicated.
  • We need to come up with a design so that the change in underlying implementation of ReportWriter will not affect the client code in any form.

Figure 3 represents a possible solution based on the idea that client at the moment requires two types of reports: HTML and Excel.

Figure 3: One possible class structure for the ReportWriter component

Although this is a possible solution, this is not a good one. We now try to test if this design passes all the principles stated in the Class Designing principles previously.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.