Contract-First Development
February 24, 2008 at 10:29 am (dotnet)
Tags: dotnet, xml
Contract-First Development (also known as Design by Contract), is a programming approach that, in the age of web services, starts with the schema used in a data exchange, and design the application from there.
I am currently using the same approach in a new personal project. As mentioned in my previous post, I am working on a prototype for an SCSF application, a Resume Builder application built on top of HR-XML standards.
I downloaded the XSD files and worked on creating the entity classes and database schema out of them. The specifications are long, so instead of doing them by hand, I decided to look for tools. For the entity class generation, I used Microsoft’s XSDObjectGen, a sample code generator for creating serializable classes from XSD schemas. For the DDL generation, I downloaded an evaluation version of the Altova XMLSpy, quite a powerful xml developer tool.
Both did a good job in rendering the XSD schemas. The problem I have, though, is that the schemas are so normalized, to the point that types that should have been, for us humans, simple enough, are rendered as separate classes and tables, like Entity ID or phone numbers. I don’t see the sense of keeping them that way as it will take a lot of connectors, even if I used an ORM like NHibernate, and it will also be slow and inefficient on the database.
I am now faced with the following choices: (1) Use a much simpler Resume schema like the XML Resume Library at Sourceforge; (2) Stick with the HR-XML schema, but code the entity classes and create the database structure from scratch manually; (3) Derive a simpler schema by taking out the normalized “simple” entities such as IDs and phone numbers and replacing them with strings - not so trivial a task as there are many throughout the entire structure; or (4) Clean up the resulting entity classes and database structure.
I have not yet decided which one to take. I am hesitant to go for Option 1 because HR-XML is an industry standard, and though large job sites like Monster.com don’t use it, there is a growing clamor to get them to adopt it. Besides, the XML Resume Library at Sourceforge has been left unupdated since 2004, probably because of the popularity of HR-XML. Option 2 is simply a lot of work. I am deciding between Option 3 and Option 4, depending on which one will be easier to do. Either one violates the XSD contract and will take some intermediate processing before the serializer can generate XML that’s 100% compatible with the schema.
Oh by the way, with regards to database generation, there’s one more issue with using Altova XMLSpy for this purpose. Because container datatypes contain the datatype itself and not a reference value like a key, the rendered tables will not have foreign keys. The relational feature of AltovaXMLSpy’s database generator will only present you with the types’ simple child types. (I believe there SHOULD be a feature that automatically creates an ID field, or identify one. There should also be intelligence in looking at relationships and deciding whether intermediate tables are necessary - ah wishful thinking.) The workaround here is probably to either violate the schema (again) by replacing the contained child types with IDs or manually add the references after the tables have been generated. I’d probably go with the latter. (Given the normalized nature of the schema, this is probably going to be almost like creating the database structure from scratch.)
Any suggestions for a better approach or a better tool (.Net for entity class generation) will be very much welcomed.
Update 02/24/2008 5:11pm
After looking through the generated .cs file and the database tables, and reading in forums, I have decided to start off with a simple structure that is loosely based on the HR-XML schema and go ahead with the development.
(I gave up when realizing that the class structures and tables are too different from each other for me to try to fix it - Option 4 as mentioned above. The class structures contained too many collection objects and enums, and the latter eliminated key information like relationships. The difficulty with dealing with the generated output also eliminates the use of tools, so modifying the schema and doing Option 3 is out.)
I also discovered that HR-XML is coming out with a more streamlined Resume.xsd version 3.0, taking out all the deprecated content in 2.* versions that have been kept for backward compatibility. They will also de-layer structure to make it XML form-tool friendly.
Check out recent developments:
http://docs.hr-xml.org/resources/HR-XML-Resume_final.pdf
http://docs.hr-xml.org/resources/HR-XML-3-0-webinar.ppt
So, it’s set. I am going to instead have my structure and create a transformation utility that will generate a compliant XML file. It will also allow for the generation of other formats, like the more popular (though less enterprise-oriented) hResume microformat.
So much for Contract-First Development. Contract Guided Development is probably more appropriate now.


