操作实体的类的名称

发布于 2024-08-25 02:49:27 字数 159 浏览 3 评论 0原文

我有一个关于命名约定的一般性问题。

如果我将数据和操作分成两个单独的类。一个类拥有数据元素(实体),另一个类操作实体类。我们通常将操作实体类的类称为什么?

(我所指的实体与任何类型的实体框架无关)

经理?控制器?操作员?操纵者?

提前致谢

i have a general question regarding naming convention.

if I separate the data and operations into two separate classes. one has the data elements (entity), the other class manipulates the entity class. what do we usually call that class that manipulates the entity class?

(the entity I am referring to has nothing to do with any kind of entity framework)

manager? controller? operator? manipulator?

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

满地尘埃落定 2024-09-01 02:49:27

这取决于您对这些数据契约/实体执行什么类型的操作。以下是我的一些约定。让我们使用 Fruit 实体的示例(我并不是试图暗示这些都是静态方法,只是伪代码):

  • Repository:在一块上提供 CRUD 操作水果
    • FruitRepository.Save(水果项);
  • Manager:简单 CRUD 之外的操作。
    • InventoryManager.ShipFruit(Fruit[] 商品,字符串地址);
  • Controller:保留在界面中使用,如模型-视图-控制器中。制定如何显示或操作水果的界面或流程决策。
    • FruitController.ShowDetails(stringfruitId);
  • 处理器:用于“批处理”在一起的操作。这些通常是长时间运行或离线完成的。
    • FruitProcessor.RemoveSeeds(Fruit[]很多Fruit);
  • Manipulator:提供对单个实体或实体集合的特定操作。
    • FruitManipulator.PeelFruit(水果项目);
  • Provider:提供更通用或全局的操作。
    • FruitProvider.GetAllTypesOfFruit();
    • FruitProvider.IsInSeason(stringfruitName);
  • Exporter:将一些水果转换为文件格式存储或转移。
    • FruitExporter.Save(字符串电子表格);
  • 分析器:提供有关单个水果或数量的结果。
    • FruitAnalyzer.Weigh(Fruit[] items);
  • Service:以松散耦合或远程访问的方式公开功能。
  • 汇编器:通过组合不同的数据源来创建水果。
    • FruitAssembler.Combine(字符串speciesFile,字符串数量File);
  • Factory:负责创建/实例化水果。
    • FruitFactory.CreateApple(); // 红色美味、麦金托什等
  • Builder:提供一种通过各个部分/属性构建水果的方法。
    • FruitBuilder.AddSeeds(5); FruitBuilder.AddStem();

这些都有些松散。主要目标是在您自己的代码库中保持一致,并避免与您正在使用的技术发生冲突 - 即。如果您正在使用 ASP.NET MVC,则不会有很多不是控制器的控制器类。

It depends on what kind of operations you're doing on those data contracts/entities. Here are some of my conventions. Let's use the example of a Fruit entity (and I'm not trying to imply these are all static methods, just pseudocode):

  • Repository: provides CRUD operations on a piece of fruit
    • FruitRepository.Save(Fruit item);
  • Manager: operations outside of simple CRUD.
    • InventoryManager.ShipFruit(Fruit[] items, string address);
  • Controller: reserved for use in the interface, as in Model-View-Controller. Makes interface or flow decisions how to display or operate on fruit.
    • FruitController.ShowDetails(string fruitId);
  • Processor: used on operations that are "batched" together. Often these are long-running or done offline.
    • FruitProcessor.RemoveSeeds(Fruit[] lotsOfFruit);
  • Manipulator: provides specific operations on a single entity or a collection of them.
    • FruitManipulator.PeelFruit(Fruit item);
  • Provider: provide more generalized or global operations.
    • FruitProvider.GetAllTypesOfFruit();
    • FruitProvider.IsInSeason(string fruitName);
  • Exporter: Convert some fruit into a format intended for file storage or perhaps transfer.
    • FruitExporter.Save(string spreadsheet);
  • Analyzer: Provides results about an individual piece of fruit or a quantity.
    • FruitAnalyzer.Weigh(Fruit[] items);
  • Service: exposes functionality in a loosely coupled or remotely accessible kind of way.
  • Assembler: Creates fruit by combining different data sources.
    • FruitAssembler.Combine(string speciesFile, string quantitiesFile);
  • Factory: responsible for creating/instantiating fruit.
    • FruitFactory.CreateApple(); // red delicious, McIntosh, etc
  • Builder: Provides a way to build up fruit by individual parts/properties.
    • FruitBuilder.AddSeeds(5); FruitBuilder.AddStem();

These are all somewhat loose. The main goal is to stay consistent within your own codebase and avoid conflicts with the technologies you're using-- ie. don't have a lot of Controller classes that aren't controllers if you're doing ASP.NET MVC.

东北女汉子 2024-09-01 02:49:27

我通常和经理一起去。

I usually go with Manager.

旧情别恋 2024-09-01 02:49:27

无论您喜欢什么名称,只要确保在整个项目中一致使用该名称即可。我们拥有的最接近的东西是 CapabilityReceiver 但即便如此,这些也不完全是您所说的。

然而。

您是否有将数据与方法分开的具体原因?除非你谈论一个类及其工厂,否则如果这种分离确实有必要,我会感到非常惊讶。

Call it whatever you are comfortable with, just make sure you use that name consistently throughout your project. The closest thing we have is a Capability or a Receiver but even then these aren't quite what you're talking about.

However.

Do you have a specific reason for separating the data from the methods? Unless you talking about a class and its factory I'd be really surprised if this separation is truly warranted.

剑心龙吟 2024-09-01 02:49:27

让我们进行如下推理:

  • 如果逻辑使用仅一个实体,请将其移动到实体本身(请参阅富域模型与贫血域模型)。

  • 因此,这些类中的大多数都实现了处理多个实体的逻辑,因此代表了协作

此类类不应根据其职责来命名。诸如managercontrollermanipulator等技术术语仍然可以用于命名约定,但重要的部分是第一部分名字。

示例:

  • 实体:产品客户
  • 两者之间的协作:PurchaseService <-- 重要的是购买,不是服务

Let's reason like following:

  • If the logic uses only one entity, move it to the entity itself (See rich domain model vs. anemic domain model).

  • So most of these classes are those which implement logic which deal with more than one entity, hence represent a collaboration.

Such class should not be named according to their responsibility. A technical term such as manager, controller, manipulator, etc. can still be use for naming convention, but the important part is first part of the name.

Example:

  • Entities: Product and Customer
  • Collaboration between the two: PurchaseService <-- what's important is Purchase, not Service
倒带 2024-09-01 02:49:27

我将数据和操作分成两个单独的类。

不。这与面向对象设计背道而驰。

I separate the data and operations into two separate classes.

Don’t. This flies in the face of object-oriented design.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文