简体   繁体   English

困惑,这是poco吗?

[英]Confused, is this poco?

Let's say that I want to implement following interface:假设我想实现以下接口:

public interface ICar
{
   bool IsMoving();
   bool IsRegistered();
   int CurrentSpeed {get; set;}
} 

   public class Car : ICar
   {
       public int CurrentSpeed {get; set;}        
       public bool IsMoving()
       {
         // some logic here
       }
   }

Does this IsMoving() method break poco definition?这个 IsMoving() 方法会破坏 poco 的定义吗?

POCO is a trait of framework design, which means that (some) code using the framework doesn't have to be adapted for it. POCO 是框架设计的一个特征,这意味着使用该框架的(某些)代码不必针对它进行调整。 Most notably, in an ORM framework, it means that the entity classes don't have to, say, implement IEntity to allow being persisted in a database.最值得注意的是,在 ORM 框架中,这意味着实体类不必实现IEntity以允许持久保存在数据库中。

This means that in your own code , you don't need to care about what is and isn't "POCO".这意味着在您自己的代码中,您无需关心什么是“POCO”,什么不是。 However, if you require other people using your code to implement ICar , then you're not allowing them to use POCOs.但是,如果您要求其他人使用您的代码来实现ICar ,那么您就不允许他们使用 POCO。

Check this link DTO ver POCO检查此链接 DTO 版本 POCO

POCO vs DTO POCO 与 DTO

The cite (but read the link and follow other links there)引用(但请阅读链接并遵循那里的其他链接)

...A POCO follows the rules of OOP. ... POCO 遵循 OOP 规则。 It should (but doesn't have to) have state and behavior.它应该(但不是必须)有状态和行为。 POCO comes from POJO, coined by Martin Fowler... POCO 来自 POJO,由 Martin Fowler 创造...

Other words, it is absolutely OK, if POCO has behavior.换句话说,如果 POCO 有行为,那绝对没问题。 The requirement for POCO is unaware of the persistence POCO The requirement不知道持久化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM