java 谁能解释一下 POJO 或 POCO 的含义和用法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4160898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can anyone explain the meaning and usage of POJO or POCO
提问by user496949
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?
我知道这些是 Mark Fowler 最近提出的概念。谁能解释一下 POJO 或 POCO 的目的及其用法?
回答by OscarRyz
Plain Old ( Java,/ CLR ) Object
PLAIN øLD(ĴAVA,/ ÇLR)Òbject
It's just a fancy name for a very basic class structure1.
这只是一个非常基本的类结构1的奇特名称。
[...]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[...]
[...] 我们想知道为什么人们如此反对在他们的系统中使用常规对象并得出结论,这是因为简单的对象缺乏一个花哨的名字。所以我们给了他们一个[...]
回答by Rex M
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.
它代表Plain Old [Java|CLR] Object,它的意思几乎就是它所说的 - 一个简单的对象,不需要任何重要的“胆量”来使其工作。这个想法与那些很难(或不能)自己实例化和操作的非常依赖的对象形成对比——它们需要其他服务、驱动程序、提供者实例等也存在。
Here's an example of a c# POCO:
这是 ac# POCO 的示例:
public class Customer
{
public string Name { get; set; }
}
And here's the hypothetical innards of a hypothetical non-POCO:
这是假设的非 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);
}
}
}
回答by Alex McBride
POCO stands for Plain Old CLR Objectand POJO for Plain Old Java Object.
POCO代表Plain Old CLR Object,POJO代表Plain Old Java Object。