Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone explain the meaning and usage of POJO or POCO [duplicate]

Tags:

java

c#

Possible Duplicate:
What does the term Plain Old Java Object(POJO) exactly mean?

I know those are recent concepts proposed by Mark Fowler. can anyone explain what the purpose of POJO or POCO and their usage?

like image 363
user496949 Avatar asked Nov 12 '10 01:11

user496949


People also ask

What is POJO and POCO?

POCO stands for Plain Old CLR Object and POJO for Plain Old Java Object.

What does POCO mean in programming?

In software engineering, a plain old CLR object, or plain old class object (POCO) is a simple object created in the . NET Common Language Runtime (CLR) that is unencumbered by inheritance or attributes.

What is POJO?

In software engineering, a plain old Java object (POJO) is an ordinary Java object, not bound by any special restriction.

What does POCO mean in C#?

POCO stands for Plain Old CLR Object, or Plain Old C# Object. It's basically the . Net version of a POJO, Plain Old Java Object. A POCO is your Business Object. It has data, validation, and any other business logic that you want to put in there.


2 Answers

P lain O ld ( J ava,/ C LR ) O bject

It's just a fancy name for a very basic class structure1.

[...]We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one[...]

like image 163
OscarRyz Avatar answered Oct 26 '22 11:10

OscarRyz


It stands for Plain Old [Java|CLR] Object, and it means pretty much what it says - a simple object that doesn't require any significant "guts" to make it work. The idea is in contrast with very dependent objects that have a hard time being (or can't be) instantiated and manipulated on their own - they require other services, drivers, provider instances, etc. to also be present.

Here's an example of a c# POCO:

public class Customer
{
    public string Name { get; set; }
}

And here's the hypothetical innards of a hypothetical non-POCO:

public sealed class Customer
{
    //can only be created by a db service layer
    internal Customer(IDbContext databaseContext)
    {
    }

    [EntityMapping("Name")]
    public string Name
    {
        get
        {
            return context.HydrateValue(this, "Name");
        }
        set
        {
            InternalNotifyRevision("Name", value);
        }
    }
}
like image 45
Rex M Avatar answered Oct 26 '22 12:10

Rex M