Random Blog from my Workday

Monday, August 04, 2008

Everybody likes to use code weaving to make software development easier - take java pojo's and hibernate and somehow magically we get that persistence functionality weaved in that allows us to load and store data to the database layer. It makes a programmers life easier but also hides a lot of the implementation into this cloud of code that we never see.

I tend to think of method calls as messages - I then also try to think of the thread as a queue. The messages are sent to the queue and executed. This makes code weaving the process of observing the queue and triggering actions when certain events happen on the queue. The action can alter, cancel, repeat or simply pass the message through.

I like that design very much - Swing for example uses the event queue for all it's messages (even adding a component to the UI tree is a message). One can easily design an application to use a similar pattern - for example, if you create a queue and messages that change your model (messages would be commands) instead of a simple API to your model you can then handle things like undo/redo through the queue messages.

The Cairngorm framework for Flex makes use of messaging as well in order to make the client/server communication and interaction with the client side model and the server side model easier.

I feel using queues and messages makes it easier for other programmers to understand what is going on in the application (the queue is a much easier concept to grasp than the code weaving).

Labels: , ,

I have been doing java swing development for the last few years - whenever I start a new contract job on an existing swing project I am usually amazed that people working with swing have never heard or seen these two articles on java.net

  1. closure style actions
    Make sure you are not writing tons of inner classes to handle your actions or even use a global event handler
  2. modify swing when the components are added
    This is great to style a component when it is added to the UI according to the operating system or make a change to a component without having to implement it for every look and feel that you support

These two articles can be a great starting point to make your life developing swing easier.