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, , .
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.
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 :) ).
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 :) ).