What should be the best practice in php to name an entry point method in a service when following DDD design principles.
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
Naming a class with a verb ( GetSinglePerson
) instead of a noun is uncommon in OO, DDD included.
Execute
is command terminology - GetX
is usually not a command but a query - see 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
.
It's really up to you. I would read over the PSR-1 Basic coding standard it has guidelines I wish we all followed. :)
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. Properties
This guide intentionally avoids any recommendation regarding the use of $StudlyCaps, $camelCase, or $under_score property names.
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. Methods
Method names MUST be declared in camelCase().
I would use index. If you're using something like laravel or codeigniter it should do the routing like /GetSinglePerson/{personId}
class GetSinglePerson {
...
public function index($personId)
{
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.