POCO explanation

I am wondering if anyone can give a detailed explanation (example) of POCO (Plain Old CLR Object). I found a brief explanation on Wikipedia , but it really does not provide a convincing explanation.

I am looking for pros / cons, implementation, manual, etc.

+20
poco
Aug 02 '10 at 23:37
source share
3 answers

Instead of calling them POCO, I prefer to call them the persistence of uninformed objects.

Because their work is simple, they do not need to worry about what they are used for or how they are used.

Personally, I think POCO is another buzzword (like Web 2.0 - don't make me start with this) for an open class with simple properties.

I have always used this type of object to store in a business state.

The main advantage of POCO is really observed when you start using things like repository template, ORM and dependency injection.

In other words, you can create an ORM (let's say EF) that distracts data from somewhere (db, web service, etc.), and then project that data into objects (POCO).

These objects can be transferred further on the application stack to the service level, and then to the web level.

Then, if one day you decide to switch to nHibernate, you don’t have to touch your POCO at all, the only thing you need to change is ORM.

Therefore, the term "stubborn ignorance" - they do not care what they are used for or how they are used.

So, to summarize, pro's:

  • Allows a simple data storage mechanism, simplifies serialization / passing through layers
  • Goes hand in hand with Dependency injection, repository template and ORM. Flexibility.
  • Minimized complexity and dependencies on other layers. (a higher level only cares about POCO, POCO does not care about anything). Loose connection
  • Simple testability (circumcision is not required for domain testing).

Hope this helps.

+37
Aug 2 '10 at 23:46
source share

You need to provide more detailed information, such as the context in which you plan to use POCO. But the main idea is that you create simple objects containing only the necessary data / code. These objects will not contain "baggage", such as annotations, additional methods, base classes, etc., which otherwise might be required (for example) for the framework.

+3
Aug 02 '10 at 23:43
source share

POCO example:

class Person { public string FirstName { get; set; } public string LastName { get; set; } public string EmailAddress { get; set; } } 
0
Aug 02 '10 at 23:45
source share



All Articles