Tuesday, January 17, 2006

ECO Adventures: Inheritance

Inheritance is one of the five pilars of Object Oriented Programming. In ECO inheritance is, I can tell you now, a piece of cake.
Consider this 'real world' model:


Developer and SalesMan inherit the behavior from Person. Developer and SalesMan are specializations of Person. Implementing this model in a VCL Win32 application using TDataSet would consider a lot of work. For instance the, in fact one-on-one relation must be maintained in the database. A person is either a Developer or a SalesMan, a person can not be both. (if you don't agree you should read this blogpost :-) )
Anyway implementing this becomes, even in Delphi with TDataSet, more complex. In ECO it is a very straight forward process.

Create the windows (ECO) application
Drop three datagrids(dgPerson, dgDeveloper, dgSalesMan) on the form and three ExpressionHandles (ehPerson, ehDeveloper, ehSalesMan) And oh, don't forget to compile first!

Setting the ExpressionHandles
ehPerson:
Name->'ehPerson'
Roothandle->rhRoot (Don't forget to set the Roothandles EcoSpaceType property!)
Expression->Person.AllInstances (Use the OCL Editor here)

ehDeveloper:
Name->'ehDeveloper'
Roothandle->rhRoot
Expression->Developer.AllInstances

ehSalesMan:
Name->'ehSalesMan'
Roothandle->rhRoot
Expression->SalesMan.AllInstances

Setting the datagrids
dgPerson:
DataSource->ehPerson

dgDeveloper:
DataSource->ehDeveloper

dgSalesMan:
DataSource->ehSalesMan

To make things complete drop two buttons for the Developer and SalesMan grid. Connect the roothandle property to ehDeveloper and ehSalesMan and set the for both buttons the property ECOListAction to Add.

Well this is pretty much it! You can see that the grids have all the appropiate attributes for their classes. By running the application we can test it:

Notice that adding a developer or salesman automatic means adding a person. So again the model does all the hard work in the background.
While still scratching the surface of ECO it becomes clear that ECO is very powerfull framework, taking a lot of the work load. Making this little application with TDataSets would be harder (although it can be done). For instance after inserting the Developer you would have to code to get a person in the person table.

Guess what: We did not code at all!

No comments:

Use an image as your UIBarButtonItem

Using an image as your UIBarButtonItem in your navigationcontroller bar can only be achieved by using a common UIButton as the BarButtonItem...