Tuesday, March 2, 2010

Domain Driven UI

Not so long back I read this book Domain Driven Design, its an awesome book and helps you understand a lot of business patterns.

Reading the book set me thinking in terms how can I be clean with respect to my Domain while not completely altering my thinking style and by leveraging the existing code.

Conceptually it says have a clear domain model which focuses on your domain instead of technology concepts and then build all kinds of persistence and presentation code around it. Once again a little common wisdom like persistence ignorance and its extension presentation ignorance comes to mind. Its easier said than done. The persistence ignorance has been tackled by many ORM frameworks such as Hibernate, iBatis, ,

This set me to think about presentation ignorance i.e. I was trying to arrive at something where the UI is completely separated from the backend code i.e. There is no need to transformation from ORM Object to Domain Object to a Data Transfer Object to a Value Object to a Page Object to Request Atribute and parameters and then have JSP. I started to think how the world would look like if the pages directly spoke to backend instead of going through a web container. 

Hmm.. I was at an IBM workshop recently and they mentioned that MQ now has its own web server so you can DIRECTLY post messages from your pages to your MQ no need to worry about writing your app. Think about it, now all that you need is for every DBMS to also have a web front-end configure queries and you are done with CRUD operations or if you are in the service world the SDOs. The reason why I state this is vendors are already going along these lines. 

Conceptually this makes things really simpler with respect to having an access integration strategy. I mean portal server JSR 168 is great but what its trying to tell you is in order for you to develop highly interactive applications that can be embedded into a single access integration layer develop it in Java. I am going to plead ignorance on JSR 286 and I am open to your views

Anyways I deviate from the core point which I want to express. My idea is to have a clear domain model and then declaratively instrument it to handle all of the non-functional requirements (network latency, usability...). Being coal-faced I started looking around for frameworks that will help me do this with my core architectural ility, Buildability :). First thing I discovered was the sophistication in Javascript by the way of JQuery. Its a great framework. I would suggest JQuery In Action  as a starting point if you seriously want to give it a shot. The next thing I discovered is JSON, as an alternative data protocol to XML. I was trying to create a Flash type application using HTML where the user interface's contract with the backend was XML except in this case JSON. Now I wanted a way to serialize Java Objects into JSON and JSON Objects back into Java so that my business logic could integrate seamlessly with my UI. (See how I used the word "seamlessly" seamlessly, I will tell you what I was thinking shortly). JSON-Lib did exactly that. 

So the big idea was to do something like this

 Domain Driven UI

So I set out to do this task to see how far I could go with my idea. What follows is how I did it and my conclusion. Of course I am not going to walk you through every detail because web is not for in-depth reading (there is a reason why the killer app is called the "Browser" - Thank you Fortune Magazine)

Listing of Instrumented HTML
Couple of things to notice here
  • AggregateRoot - Domain Driven Design Terminology to specify the standalone root of a business entity. In this case this is a heuristic to the Javascript to utilize root from the JSON being marshalled
  • domainEntity - Specifies the Object type that is being painted, you can paint more than one type of domainEntity
  • Field Names are then directly mapped to the appropriate attribute names i.e. when you see a firstName it directly maps to Person.firstName, again you can have a mix and match of attributes here too
  • Option List - This is a service call to get the information for this reference data by asking for Person.gender so the page creation remains independent of your representation
  • The input heuristic is also used in packing the json back when information needs to be sent to server.
(If you are too interested in this, send me a note I can walk you through a more detailed example).

Now let me show you what the code does. I plugged in a custom Request Processor that would take in the JSON and convert it into object. The seamlessness done through reflection (Doh !!). I use a bunch of custom forwards to inform my processor of the Domain Object to use and then use the converter to convert it

Listing of the Domain Based Custom Struts Request Processor
Why did I use Struts: remember my constraint Buildability ? Ok.. so I have all this now how does the processing logic look like ? The business logic works of pure domain objects. Notice the complicated business logic of printlns using the object directly
Listing of Struts Action

Finally the output JSP merely streams out the HTML. Here is the struts-config listing of a sample action

Listing of Struts Config
My conclusion was I was able to do this pretty successfully. The only cons I could think of was
  • Performance issues because of reflection
  • Too much of work done on the front end and requires some heavy lifting on javascript
  • Some discipline with respect to how to name the form fields
But the pros just outweigh the cons in my mind. I am not able to think of any other reasons. Not to mention, I could write up a google gadget of my UI and embed it into you know where. You could also have a true portal architecture where I could have interactive portlets

What issues do you see ? Is there something I am missing ? Are there frameworks available that already do this (Other than Naked Objects). Dont also tell me about JSF or Ext JS I am not ready to write something that writes something that generates something and the generated something generates HTML. What are your views, shoot back. If you want the complete sourcecode or eclipse project shoot me a note with your name number (and credit card number :) ).

Friday, February 26, 2010

Holistic SOA - Financial Perspective

Expanding on the BSC. For each of the blocks in various perspectives, the BSC recommends having the following 4 things
Objective - Intent for conducting an activity that the organization plans to accomplish. These are vision/mission type of statements for an organization Ex: Reduce Cost
Initiatives - Projects / initiatives that the organization should embark on so as to achieve the objective
Measures - Various Performance indicators that will help in measuring the success of such initiatives. These indicators can be subdivided into Lead and Lag indicators. Put simply, if your objective is reduce your weight, then you need to reduce calories intake and burn more through exercise. In this case your weight is the lag indicator and the calories intake and calories burnt are lead indicators as they LEAD you to loosing weight (theoritically).
Targets - The specific targets that the organization would like to set for the current year or the next 3 years.

The important thing to understand is the Objective and Targets are specific to an organization whereas the Measures and Initiatives are not (atleast for a fairly horizontal effort such as SOA which is very much like software development i.e. business agnostic). Put another way, things like reliability may have different targets in different industries but how you measure it is typically the same

The reason I mention this is I will try to elaborate on the perspectives while focusing on the initiatives and performance indicators and try to link them together to form the lead lag chain but not the other two. My intention in doing that is to
  • Backtest the initiatives with what is going on the industry and supplement it based on the feedback
  • Facilitate a pallette of initiatives so organizations can choose to adopt along with the indicators
  • Backtest the indicators to firm up that list
 Financial Perspective

Ok, so financial perspective seems to be mentioning a lot of generic terms i.e. Reduce Cost, Generate Revenue etc. These are really generic to what every business does so how does SOA help in any of this ? Let me first of all take the chance to define what I mean by these terms so that we are semantically interoperable :). Let me start with defining these objectives first

Reduce Overall Cost - Reduce the total cost of creating a sellable unit. In the case of SOA this sellable unit happens to be the service. So this objective is about reducing
Change Channel Mix to Increase Revenue - Have a multichannel strategy where you can not only sell through your own website (B2C) but through other people's websites (B2B) and mobile based transactions to get to more people (and make more money)
Reduce Operating Expenses - Wait, didn't we talk about this in Reduce Overall Cost. Ok, the operating cost is the money required to maintain the transaction from Supply to the Demand. Simply put this is the cash (to supply) to cash (from demand) cycle. 
Reduce Risk - Reduce the risk in the transactions by being compliant with regulatory organizations i.e. PCI, PII, the usual suspects

So what initiatives can we do to achieve these objectives ? It depends on the IT operating model you have. These are defined below

Initiatives for Financial Perspective
Explanation for each of these initiatives are expressed in the table below.
Initiatives Definition and Purpose

In the next article I will try to break out the indicators for each of these initiatives

What do you think ? Are there any initiatives I am missing or have misplaced ? Are there more indicators than those that are currently expressed ? Any real world case study you are aware of ? Shoot back.

Tuesday, February 23, 2010

Holistic SOA

Sometime back I was made part of a SOA CoE (Center of Excellence) and we were tasked to take the SOA program for the organization forward. I had recently read the book EA as Strategy and Leveraging the new Infrastructure and I was trying to understand how these concepts play in SOA. I ran into this Blog which made an excellent point how in certain organizations certain initiatives are successful but in some they mean different things.
I started to think about how can I frame this effectively so that it doesn't give a narrow meaning to the program but has widespread implications to the organization. Then almost by accident I ran into Balanced Score Card(BSC). The book by Kaplan and Norton gives a great introduction. The framework nicely framed up the various tenets in the enterprise and how they play into satisfying the ultimate common goal for commerical organizations i.e. "Show me the money". Organizations use BSC to prioritize and align the various initiatives in the organization to the common goal.

Balanced Score Card

This led me to think, I were to think of the CoE as a business then it would have similar characteristics, granted it would be business agnostic mostly but it would effectively help me in understanding what value can I drive out of SOA. It led me to the construction of my first BSC for SOA given below
SOA Balanced Score Card

In the days to come I am planning to expand out these perspectives into initiatives that can happen in the organization. What are your thoughts on this ? Does such a framework exist ? Are there things I am missing from this scorecard that needs to be included ? Shoot back