Tuesday, June 30, 2009

Template Based Design Technique - Part 1

Challenge of scalability, flexibility, performance and decoupling. To tackle few of these challenges, I have developed my own pattern. One of such pattern is Template driven design.

Let us take an example to understand the challenge and then ways to resolve the same. We all are very familiar with Microsoft Word. It provides ways to create a document-using template. Suppose I wish to create my resume, I can use one of the several resume templates it provides to make one for mine. Essentially this process can be depicted in following picture:



Figure 1

In this process “Resume Template” and “Resume” have separate and distinct life cycles. Destruction of “Resume” does not affect “Resume Template”. Similarly destruction of “Resume Template” does not affect “Resume” once it is created.


Now let us take the same argument a bit further. The advance users of MS Word are also aware that they can make template itself. Essentially they can act as Angle for resume creators. So now keeping Template creation facility in view the whole process can be depicted as:



Figure 2

The “Template creator” acts as Angle for resume creators (assuming template creator can not add fields which go beyond imagination of “Template creator”). The benefits of this pattern are very straightforward.

1. If God is imaginative enough he can accommodate all type of fields in his template. We can consider God imagination as Master Template, which gives wisdom to Angles to create Templates (Essentially we need mechanism to add fields in God’s Master Template as GOD can also lean new tricks over time period).
2. God can appoint various Angles (Template Creators) to create templates for specialized purpose.
3. Mortals (Resume creators) can use one of the “Resume Template” and can create various resumes.

So now question arises how to implement same design pattern in an business application which may be web based or not. For simplicity purpose let us assume the application is a web application and again it is again a resume making service.

So from process perspective this application can be depicted as:



Figure 3

This picture shows only simple flow. In real life there should be ways to perform CRUD operations on resume templates as well as on resumes. In truly flexible application even God’s list must be updatable.

So, how to resolve these challenges?

I will prefer step approach. In first step I will go with all knowledgeable God. List of attributes is final; it will remain same for ever. No changes in this list. In programming terms if any change is required in “Master Template” you need a developer.

So God decided that in resume you can have following fields at the most

1. Name
2. Physical Address
3. Telephone Number
4. Education
5. Employment History

So Angles (Template creators) will see following page:



Figure 4

Now template creator creates two templates, which have following values:

First Template

Template Name: Template-1
Template Description: Resume for fresh graduates
Candidate’s Telephone Number: Yes
Candidate’s Education History: Yes
Candidate’s Employment History: No

Second Template

Template Name: Template-2
Template Description: Resume for experienced
Candidate’s Telephone Number: Yes
Candidate’s Education History: Yes
Candidate’s Employment History: Yes

Now a candidate visits our Resume Service application. He sees two pages, which essentially show two templates created so far.



Figure 5



Figure 6

Suppose candidate who is visiting our application is fresh graduate so he fills up resume template for fresh graduate (Template-1) with following values:

Resume Name: FirstResume
Resume Description: Raj’s First Resume
Name: Raj
Physical Address: B-24, Block 13, Sector 86, Delhi 201001
Telephone Number: 987-654-3210
Education History:



Figure 7

When our candidate have looked at his resume he sees following:



Figure 8

To realize this application, traditional approach of storing data in RDBMS and creating dynamic HTMLs (using JSP, ASP, PHP, etc) will be quite difficult due to real life complexities of Master template and templates.

So what is the answer??

I will cover solution of this challenge in my one of future post.

No comments:

Post a Comment