# Object-Form mapping

DevFeed: [Object-Form mapping](<https://devfeed.tech/articles/object-form-mapping-33353.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2010/10/19/object-form-mapping>)

Published: 2010-10-19T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [Forms](<https://devfeed.tech/topics/forms.md>), [ASP.NET](<https://devfeed.tech/topics/aspnet.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Object-relational mapping](<https://devfeed.tech/topics/orm.md>), [business logic](<https://devfeed.tech/topics/business-logic.md>), [PHP](<https://devfeed.tech/topics/php.md>), [unit tests](<https://devfeed.tech/topics/unit-tests.md>)

Tags: [asp-net](<https://devfeed.tech/tags/asp-net.md>), [business-logic](<https://devfeed.tech/tags/business-logic.md>), [form](<https://devfeed.tech/tags/form.md>), [forms](<https://devfeed.tech/tags/forms.md>), [orm](<https://devfeed.tech/tags/orm.md>), [php](<https://devfeed.tech/tags/php.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

## AI overview

This article discusses object-form mapping between HTML forms and application objects. It describes ASP.NET's FormView and ObjectDataSource approach, compares it with Ruby on Rails conventions and a similar PHP approach, and argues that marshalling form parameters into objects can simplify page flow and support testing business logic.

## Source excerpt

I'm pretty sure most developers (web developers anyway) have heard of ORM (Object Relational Mapping) tools like NHibernate that map your database tables and to objects. These ORM tools reduce interaction with the database to just a few method calls, many times just Save(), GetById(), and a few custom query methods. There's a lot written about ORM, but no one really writes about the mapping between HTML forms and the objects that ORM maps.ASP.NET has a great solution for OFM (I'm calling it OFM because google won't give me a real name for it). If you use a FormView in combination with an ObjectDataSource you can bind the properties of your object to form elements. This is pretty cool because it reduces your code to writing an ORM mapping, creating factory methods to get and save the object, and some ASP markup that maps the object to HTML elements.I was playing with Ruby on Rails which has a somewhat different approach to OFM. Basically you write regular HTML and give your form elements names like "account[id]", "account[name]", etc. This seems like a little more work than the ASP.NET way except that on the server side it uses this notation to wrap the query string into an object that can be referenced in object notation from ruby code like "account.id", "account.name", etc. I believe PHP does something similar. I like this method because it's very light on HTTP - there's no obstructively bloated view state being passed around like there is in ASP.NET and you can pass several objects through the query string.Basically, OFM manages some of the page flow by marshalling form parameters into objects that can easily be passed to a factory method. This is awesome because it means I can focus more effort on writing unit tests for business logic that has no dependencies on the web API. It allows me to to keep page flow simple and sets up business logic for creating restful web services (seriously, you could just slap [WebMethod] attributes on the factory methods and voila y