Wednesday, January 30, 2008

Basic Form/UI Object

Object Oriented Programming(OOP) is common in todays programming language, such as .Net, Java and C++. Therefore, it is common to use OOP to solve business logic problem via creating business object(BO). On top of that, database design also cater for OO in order to easily interact between data object and BO. Mapping BO to UI/form somehow has not been taking too much consideration. Here, I would like to share the basics(I think) form object, which I learn from my senior (Danny Lim) in my working experience and I find it worth sharing.

First, business process are stored in methods instead under events. E.g. Click on save button and insert a new record inside that event method. The appropriate way should be click on save button and call the save record method. This way the save record method can be shared by others and the UI is only for interaction, not for operation. Therefor, the UI only capture the user input and pass/read value to/from the BO. Below is the list of methods and properties of the form object

1.Public Property FormState as enum
After the form object is created, the FormState will be assigned with enum value of Add, Edit or View(or more if you want to). The FormState is for set up the UI control. With Add state, all controls on the form are cleared. Edit, value are load to the control. View, controls are disabled for reading. This also mean one form is used for 3 different operation. (Delete does not require a form, usually)

2.Method SetControl
Based on the FormState, the controls will be set accordingly. Example: Add state, all controls are enabled. Edit, partial controls enabled. View, all disabled.

3.Function ShowForm (business object) return boolean
When the form object is created and called, BO is passed into for process. The return boolean is to confirm the process is successful.

4.Method ObjToUi
Object value is mapped and passed to UI controls.

5.Method UiToObj
UI control value is passed back to BO.

6.Function Validate return boolean
After user click on save, value on controls will be validated and business object validation logic stored in the object will be called and verified.

Update: Sample file has been re-uploaded to http://www.mediafire.com/?lxy9bmmnnsz