Can someone define what exactly 'POCO' means? I am encountering the term more and more often, and I'm wondering if it is only about plain classes or it means something more?
-
32It's also funny that "poco" is a Spanish word meaning "little, not much". So, it fits this context nicely! en.wiktionary.org/wiki/poco– EnocNRoll - AnandaGopal PardueApr 8, 2010 at 14:30
-
8It means the exact same thing in italian too :)– BlackBearJan 31, 2012 at 18:40
-
3And in Portuguese means a error because it is spelled: "pouco".– IsmaelSep 27, 2012 at 14:56
-
4In Polish "POCO" is question "Why use it"– titolAug 20, 2016 at 21:00
-
Just happens to fly by the POCO stuff. The official document now has the definition: A POCO—or a plain old class/CLR object—is a .NET data structure that contains only public properties or fields.– victor6510Jun 28, 2022 at 5:07
11 Answers
"Plain Old C# Object"
Just a normal class, no attributes describing infrastructure concerns or other responsibilities that your domain objects shouldn't have.
EDIT - as other answers have stated, it is technically "Plain Old CLR Object" but I, like David Arno comments, prefer "Plain Old Class Object" to avoid ties to specific languages or technologies.
TO CLARIFY: In other words, they don’t derive from some special base class, nor do they return any special types for their properties.
See below for an example of each.
Example of a POCO:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
Example of something that isn’t a POCO:
public class PersonComponent : System.ComponentModel.Component
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string Name { get; set; }
public int Age { get; set; }
}
The example above both inherits from a special class to give it additional behavior as well as uses a custom attribute to change behavior… the same properties exist on both classes, but one is not just a plain old object anymore.
-
17I would view a POCO as a plain old class that doesn't try to be part of the trendy pattern set. However I like your answer too. Oct 30, 2008 at 12:40
-
1Agreed - not a fan of the C# name, but that was what I first heard when I was wondering about the question :) Class then fits POJO, POVBO POC#O, POC++O, PORO, etc. Oct 30, 2008 at 12:51
-
14This doesn't really give a good answer in my personal opinion as someone also curious. Ok, so no attributes describing infrastructure (what do you mean by attributes and infrastructure...a DB connection for example? what? example please). What responsibilities should your domain objects not have? So POCO is a domain object (BL object) basically? So really POCO is just another acronym for a Business Layer Object / Domain Object which all mean the same damn thing. POCO / Business Layer Object / Domain Object == same damn thing, just 3 different acronyms for the same concept right? Dec 21, 2010 at 6:04
-
5this reply tells me absolutely nothing about what it is in the real world...just a definition that anyone can look up on Wikipedia. How's about some example POCO classes?? and why they are POCO in context. Dec 23, 2010 at 15:20
-
2As an example, a class you wrote that only inherits from
System.Object
is a POCO. If it inherits fromExternalFramework.OrmMapperBase
or something like that, it isn't a POCO anymore. Dec 17, 2014 at 17:19
Most people have said it - Plain Old CLR Object (as opposed to the earlier POJO - Plain Old Java Object)
The POJO one came out of EJB, which required you to inherit from a specific parent class for things like value objects (what you get back from a query in an ORM or similar), so if you ever wanted to move from EJB (eg to Spring), you were stuffed.
POJO's are just classes which dont force inheritance or any attribute markup to make them "work" in whatever framework you are using.
POCO's are the same, except in .NET.
Generally it'll be used around ORM's - older (and some current ones) require you to inherit from a specific base class, which ties you to that product. Newer ones dont (nhibernate being the variant I know) - you just make a class, register it with the ORM, and you are off. Much easier.
-
4just for the sake of completeness, CLR stabds for Common Language Runtime - the .net virtual machine.– philantOct 30, 2008 at 14:05
-
5.Net 3.5 sp1 ORM example: the Entity framework requires that classes inherit from a certain framework class. LINQ to SQL does not have this requirement. Therefore LINQ to SQL works with POCOs and the Entity framework does not.– LucasMay 27, 2009 at 16:05
I may be wrong about this.. but anyways, I think POCO is Plain Old Class CLR Object and it comes from POJO plain old Java Object. A POCO is a class that holds data and has no behaviours.
Here is an example written in C#:
class Fruit
{
public Fruit() { }
public Fruit(string name, double weight, int quantity)
{
Name = name;
Weight = weight;
Quantity = quantity;
}
public string Name { get; set; }
public double Weight { get; set; }
public int Quantity { get; set; }
public override string ToString()
{
return $"{Name.ToUpper()} ({Weight}oz): {Quantity}";
}
}
-
5This should be the accepted answer. It provides the actual explanation (It has no behaviors) and also has an example for better understanding what a POCO looks like. Apr 18, 2018 at 14:33
-
1
-
3I would argue about a POCO not having behaviour. It is simply a class what doesn't depend on other framework/library than .Net. I.e. the File class is POCO, but DbContext is not because depends on Entity Framework. Jul 20, 2019 at 10:49
-
1A POCO class can definitely has behavior (validation, calculation, transformation...) as long as the behavior doesn't depend on anything else than CLR basic types (string, int, bool...) and sibling POCO classes. Mar 31, 2021 at 10:31
POCO stands for "Plain Old CLR Object".
-
26
-
29And as my high school electricity teacher would say, "...and oranges taste orangey"– Ian BoydJul 2, 2011 at 18:52
-
9Right, but this post looks like more a comment, rather than an answer since it does not completely answer the question. Dec 20, 2013 at 15:19
-
To add the the other answers, the POxx terms all appear to stem from POTS (Plain old telephone services).
The POX, used to define simple (plain old) XML, rather than the complex multi-layered stuff associated with REST, SOAP etc, was a useful, and vaguely amusing, term. PO(insert language of choice)O terms have rather worn the joke thin.
In Java land typically "PO" means "plain old". The rest can be tricky, so I'm guessing that your example (in the context of Java) is "plain old class object".
some other examples
- POJO (plain old java object)
- POJI (plain old java interface)
Interesting. The only thing I knew that had to do with programming and had POCO in it is the POCO C++ framework.
Whilst I'm sure POCO means Plain Old Class Object or Plain Old C Object to 99.9% of people here, POCO is also Animator Pro's (Autodesk) built in scripting language.
POCO is a plain old CLR object, which represent the state and behavior of the application in terms of its problem domain. it is a pure class, without inheritance, without any attributes. Example:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}