Recently, I announced a blog series on making use of Lookup API along with some design patterns in RCP Apps. So, I thought why not get started by porting some basic code snippets onto NetBeans Platform and then I shall see how to go about evolving them.
I will be beginning with Builder Pattern (a type of Creational Patterns). It does seem obvious with the title of the post- “Building” Pizza with Lookup.
The intention is to abstract steps of construction of object so that different implementations of these steps can construct different representations of objects.
Well, I came across a code sample which creates different types of Pizza using Builder Pattern. Hey, I have never made any Pizza on my own, but this seems to be a golden chance and that too through coding ;)
- Run “NetBeans IDE” (I am using 6.5) which I had installed using JDK 1.5.10.
- Next, press Ctrl + Shift + N or goto File > New Project…
New Project Wizard opens…
- Choose NetBeans Modules as Category and NetBeans Platform Application as Project.
Name and Location Wizard opens…
- Fill relevant information, and you would see project opens up in NetBeans Project Window (Ctrl + 1).
Right-click Project Node and see Project Properties, then select Libraries from visible Categories.
Now, you would see on the right-hand side, only some of the modules of platform9 cluster that are included by default in a RCP Application. Java Platform pointing to JDK 1.5 by default.
Overview of the Code Sample
The existing code sample has 6 classes, out of which 5 fit into Builder Pattern and the remaining class just runs the code sample to construct one of the types of pizza.
Abstract interface for creating objects (product).
Concrete Builder (HawaiianPizzaBuilder, SpicyPizzaBuilder)
Provide implementation for Builder. Construct and assemble parts to build the objects.
The Director class is responsible for managing the correct sequence of object creation. It receives a Concrete Builder as a parameter and executes the necessary operations on it.
The final object that will be created by the Director using Builder.
The code above could be split into 6 separate “.java” files and stored under single package OR they could be inside a single “.java” file, wherein the filename would be same as that of the Main class.
Porting to NetBeans Platform
Assuming you have followed the guidelines stated in “Getting Started” section and have created a default NetBeans Platform Application (I have named it PizzaBeans) with “No Modules”. Now, we will create 3 modules and finally, move towards creating the 4th module, the one that interacts with the client.
To be continued…