Friday, December 14, 2007

What is Pattern Programming about?

NOTE: "XML-Driven Design" blog is complementary to this blog.

Introduction

After a couple of years of developing J2EE components, Web Services, Web and mobile applications, I started to use a new approach when designing and developing applications. This approach allowed me to developed quickly different versions of the same applications for different clients (web, stand alone and mobile) and as a second result it reduces the application's maintenance cost.

I call this new approach "Pattern Programming" and it works in conjunction with something I call "XML-Driven Design".

NOTE: "XML-Driven Design" has a secondary role in this approach because it's just an implementation of my concepts using XML as a "tool" for the design process. So, later I may define another tool for designing and I'll probably call it "something-Driven Design".

This new concept can be expressed in just one sentence:



All the code in your application MUST be based in a scalable, reliable and well tested pattern.

P-e-d-r-o A-c-u-n-a


This sentence seems very evident, but it's difficult to achieve because most of the applications have 20% of the code based in well known patterns and 80% based in new algorithms.


We should analyze every new algorithm and identify the pattern behind it.

P-e-d-r-o A-c-u-n-a


UML is a good way to "document" a pattern, but doesn't generate code. So, programmer must code a pattern based in their previous experiences and that could be a source of error or way to break a good pattern.

I found a practical way to analyze new algorithms and transform them in pattern that can be used to generate code that other programmers can use. When a programmer see the benefit of using this new approach they also want to code patterns.

A practical example

Let me start with a simple example that will give you an idea of what I'm talking about. I'm going to develop an Google Android application that will use geographical data generated by a server side application (web application) and display it using a MapView component. This application will be 100% generated by patterns. There will not a simple line of this application that is not based on a well tested and known patterns. We are going to spend some extra time in the design process, but the process of coding will take just a few minutes. And we can regenerate the whole application at any time, so we can tune some properties and see the results.

Let's start. We are going to code an "Android Activity" that requests some data from the server and displays it on the screen.

Note: At this moment, the Google Android core doesn't provide "WS Client" native support, so I can use an XML document to exchange data between the "Android Activity" and the server side applications. I'm going to call this XML document a "transaction". The structure of every "transaction" will be: