Explanation of POCO

Instead of calling them POCOs, I prefer to call them persistence ignorant objects.

Because their job is simple, they don’t need to care about what they are being used for or how they are being used.

Personally I think POCOs are just another buzzword (like Web 2.0 – don’t get me started on that) for a public class with simple properties.

I’ve always been using these type of objects to hold onto business state.

The main benefits of POCOs are really seen when you start to use things like the repository pattern, ORMs and dependency injection.

In other words – you could create an ORM (let’s say EF) which pulls back data from somewhere (db, web service, etc), then project this data into objects (POCOs).

These objects can be passed further down the app stack to the service layer, then onto the web tier.

Then if one day you decide to switch over to nHibernate, you should not have to touch your POCOs at all, the only thing that should need to be changed is the ORM.

Hence the term ‘persistence ignorant’ – they don’t care what they’re being used for or how they are being used.

So to sum up, the pros:

  • Allows a simple storage mechanism for data, simplifies serialization/passing around through layers
  • Goes hand in hand with depedency injection, repository pattern and ORMs. Flexibility.
  • Minimized complexity and dependencies on other layers. (higher layers only care about the POCOs, POCOs don’t care about anything). Loose coupling
  • Simple testability (no stubbing required for domain testing).

Hope that helps.

Leave a Comment