Archive for March, 2009

ITworks Design Journal: Spaghetti Code

This post is part of the “ITworks Design Journal” series.

After deciding on a language and framework for the new inventory/work order application, I started to write some code. I wrote a couple of samples just to get the hang of the widgets and how handlers worked and all that jazz. Before long, I sat down to begin the application proper.

It didn’t take long to realize that something didn’t feel right. My default Application implements EntryPoint object was building my UI, creating the login dialog box, and a bunch of other stuff. I tried to use classes to separate it as much as possible, but it just wasn’t working out like I wanted.

Then, I discovered an overview of the GXT MVC classes, guided by the sample Mail application that comes with GXT. I didn’t even know that GXT had a set of MVC classes. After reading over the tutorial, I set to work rebuilding the application using a MVC pattern.

For the uninitiated, MVC stands for "Model View Controller" and is a way of organizing your code into classes that have specific roles1:

  • Models are domain-specific representations of information. Logic attached to your model gives meaning to the raw data it contains.
  • Views render the model in a form suitable for interaction (in this case, the rich web UI). A single model may have multiple views for different purposes. Views are responsible for capturing user interaction.
  • Controllers are responsible for the business logic–they process commands and events and indirectly make changes to the model.

In GXT, there is a Dispatcher singleton that is used to dispatch events to controllers, which can register themselves to certain event types. Application control is handled by firing events which are handled by controllers, which in turn process business logic, update models, and finally pass events on to the view which then updates the UI and waits for the user to interact with the application in some way.

Using this design pattern really increased code readability and made it much easier to organize my thoughts.

  • (Root) The application starts by creating the controllers and firing the "Init" event using the Dispatcher.
    • (AppController) The controller for the application, AppController, receives the "Init" event
    • (AppController) The application controller creates its view and asks the Dispatcher to fire the "Login" event.
  • (Root) The Dispatcher fires the "Login" event.
    • (LoginController) The login controller receives the event and initializes its view.
      • (LoginView) The login view creates its model (a "User") and its UI (LoginDialog) and waits for the user to entier their credentials.
      • (LoginView) The view captures the user’s input and asks the model to authenticate. If successful, the view hides the dialog box and asks the Dispatcher to fire the "BuildUI" event, signalling that the next phase of the application should start.
  • (Root) The Dispatcher fires the "BuildUI" event.
    • (AppController) The application controller also processes this event and simply passes it to its view (nothing to do on the business logic side).
      • (AppView) The application’s view builds the basic UI.

And so forth and so on. This pattern allows you to keep every piece of the application completely separate, and still provides a way to communicate between them (via the Dispatcher) if necessary.

1 http://en.wikipedia.org/wiki/Model–view–controller

, , , , ,

No Comments

ITworks Design Journal: Language and Framework

This post is part of the “ITworks Design Journal” series.

We currently use an enterprise-level application for managing work orders, and an in-house web site for managing assets. After sitting down and looking at these two systems, we came to the conclusions that (1) the work order system was more powerful than we needed, and we were likely paying too much for it, and (2) the asset system was too simple and difficult-to-use (very form-based layout). It didn’t take long to decide the following:

  • I wanted the new app to be web based, allowing for use anywhere without installation
  • I wanted the new app to use a rich web UI
  • I wanted the new app to be exactly as complex as we needed it to be, but no more
  • I wanted the new app to be expandable as easily as possible

As the IT sat down and began to brainstorm what features we wanted the app to have, I started thinking about languages and frameworks. PHP has always been my favorite server-side language, and the only web UI framework I had used to any extent was the Yahoo! UI library.

After some research, I discovered the Google Web Toolkit, or GWT. I had actually heard of it before, but passed it up as I didn’t read enough about it to fully understand what it was. It didn’t take me long to find the following on thier site:

With Google Web Toolkit (GWT), you write your AJAX front-end in the Java programming language which GWT then cross-compiles into optimized JavaScript that automatically works across all major browsers.

The very idea intrigued me; I downloaded the toolkit and installed Eclipse (I haven’t written Java in a very long time), and started following along with the sample tutorial.

In the end, I was very impressed with GWT. The ability to debug a web application just like you would a Java application (after all, in the GWT shell, it is technically a Java application!) was a huge boon, and being able to make a change in the Java code and simply refresh the included hosted-mode browser to see the change saved so much time.

The one thing I didn’t like about GWT was the look and feel. What “widgets” it does include are very HTML-ish and don’t feel rich at all. So, some more searching, and I discover Ext JS, a javascript UI library that looks very nice. A little more time spent looking around their site revealed an amazing and very cool piece of information–they have a version of their UI library designed specifically to work with GWT!

After downloading and installing the GXT library, I was sold. The UI was beautiful, and between GWT and GXT, Ajax data loading and display is a breeze.

My decision was made: GWT/GXT would be my front end framework of choice; I decided on PHP for the server-side layer, as it is my favorite server-side scripting language and I am very familiar with it. It was time to write some code.

, , , , ,

No Comments

ITworks Design Journal

Where I work, I am helping to design and implement a piece of software for us (the IT department) that allows us to manage and track assets and work orders. I have decided to keep an ongoing journal, of sorts, regarding the design of this software, partially because some people may find it interesting and/or useful, and partially because I myself may learn something by forcing myself to repeat my thought process.

You can find all the posts in this series by viewing the tag “itworks-dev,” and there is also a tag-specific RSS feed if you are so inclined to follow this journal specifically, although the posts will also show up in the general RSS feed.

,

No Comments