Monthly Archives: August 2011

A simple definition and example of a POCO object in .NET

It shouldn’t be so difficult to find an article on POCO that actually explains what it is and gives an example. So to make the world a better place, here ya go:

(From Wikipedia)
Plain Old CLR Object or POCO is a play on the term POJO, from the Java EE programming world, and is used by developers targeting the Common Language Runtime of the .NET Framework.

Similar to the Java context, the term is used to contrast a simple object with one that is designed to be used with a complicated, special object frameworks such as an ORM component. Another way to put it is that POCOs are objects unencumbered with inheritance or attributes needed for specific frameworks.

So what does this mean?

A POCO object is one that doesn’t rely on a framework to exist. For example, a WebForm object relies on the Web.UI.Page object which relies on an entire ASP.NET framework and therefore is not a POCO object.

What different does this make?

Well, if I’m writing a WCF Service that I want to return an object, it wouldn’t do much good to return an object that relies on a framework (or contains abstract methods or properties that point to nothing outside of the original environment) that the consumer may not have access to. But, if I create a simple object, such as one that contains mostly properties and a little business logic, I can easily return this from a WCF Service and use it in pretty much any application I want (Web, Desktop, Windows Service, Silverlight, other WCF services, …).

This is my understanding and I welcome further input.