简体   繁体   English

PHP DDD如何命名入口点方法?

[英]PHP DDD how to name entry point method?

What should be the best practice in php to name an entry point method in a service when following DDD design principles. 在遵循DDD设计原则时,php中最好的做法是在服务中命名入口点方法。

Same as class: 与班级相同:

class GetSinglePerson {
     ...

     public function getSinglePerson($personId)
     {
     }
}

Command pattern: 命令模式:

class GetSinglePerson {
     ...

     public function execute($personId)
     {
     }
}

Adapter pattern: 适配器模式:

class GetSinglePerson {
     ...

     public function handle($personId)
     {
     }
}

Some remarks that won't fit in a comment ;) 一些评论不适合评论;)

  • DDD is not an architecture DDD 不是架构

  • Naming a class with a verb ( GetSinglePerson ) instead of a noun is uncommon in OO, DDD included. 在包含DDD的OO中,使用动词( GetSinglePerson )而不是名词命名类是不常见的。

  • Execute is command terminology - GetX is usually not a command but a query - see CQRS . Execute是命令术语 - GetX通常不是命令而是查询 - 请参阅CQRS

  • One-method services are uncommon, not to mention services named after the only operation they expose. 单方法服务并不常见,更不用说以它们公开的唯一操作命名的服务。 Usually you would group operations together into something with a higher level name like PersonService . 通常,您可以将操作组合为具有更高级别名称(如PersonService

It's really up to you. 这完全取决于你。 I would read over the PSR-1 Basic coding standard it has guidelines I wish we all followed. 我会阅读PSR-1基本编码标准,它有我希望大家都遵循的指导方针。 :) :)

As long as you are consistent, that's what counts. 只要你保持一致,那就重要了。

This paragraph in particular sticks out to me and applies in this question/situation. 本段特别适用于我,并适用于这个问题/情况。

4.2. 4.2。 Properties 属性

This guide intentionally avoids any recommendation regarding the use of $StudlyCaps, $camelCase, or $under_score property names. 本指南有意避免任何有关使用$ StudlyCaps,$ camelCase或$ under_score属性名称的建议。

Whatever naming convention is used SHOULD be applied consistently within a reasonable scope. 无论使用何种命名约定,都应该在合理的范围内一致地应用。 That scope may be vendor-level, package-level, class-level, or method-level. 该范围可以是供应商级别,包级别,类级别或方法级别。

4.3. 4.3。 Methods 方法

Method names MUST be declared in camelCase(). 方法名必须在camelCase()中声明。

I would use index. 我会使用索引。 If you're using something like laravel or codeigniter it should do the routing like /GetSinglePerson/{personId} 如果您正在使用laravel或codeigniter之类的东西,它应该像/ GetSinglePerson / {personId}那样进行路由

class GetSinglePerson {
     ...

     public function index($personId)
     {
     }
}

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

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