Step 5a: Refined Design, class URLCharacter previous   contents   next
next 

First we need to decide about the visibility of the classes. The class URL must be public. InvalidURLExceptions thrown by the parser should also be public to inform the user about parsing failures. The remaining classes URLCharacter and Parser will be made package private to hide the parser details from the user:

  1. Show the Editor Pane
    If the source code of a class is not shown if you click on a class element, select 'Editor Pane' from the 'View' menu. Now a click on a class element should show the class' sourcecode.

  2. Edit the Properties
    Instead of deleting the 'public' modifier from the classes in the source code, you can right-click a class and select the 'Visibility' submenu. Mark 'Package Local' in the submenu or use the 'Properties...' option from the context menu and deselect the 'public' checkbox.


    (click on the image for a fullsize screenshot)

To implement test-driven development from XP, it would now be time to create the first test cases. The required functionality is defined by the tests in that they are designed to fail until the functionality is implemented. So the implementation is done as soon as all tests run successfully.
To compile the tests, we need minimal method bodys in the tested classes. Since we know from the grammar which methods have to be implemented for the parser, we will add the method signatures with minimal bodies to the classes in the de.extremejava.url packge first.

The necessary methods of the class URLCharacter are defined by the character classes in the RFC grammar. We will name the methods according to the pattern is<character class>(). Most methods will get a single character as argument. However, escaped characters are a special case because they consist of a '%' and two hex digits. For methods which check for escaped characters, the argument will be a string. Since URLCharacter contains only helper methods, we will make the default constructor protected and all other methods static public.

The fastest way to implement the initial method versions will be to copy and paste Java oneliners in the source code of the URLCharacter class like this:


(click on the image for a fullsize screenshot)

Now we will do the same for the parser.

  previous   contents   next
next 

© 2001 A. Heilwagen