parent
1ab28cb1e5
commit
bfa27dea9f
1 changed files with 42 additions and 0 deletions
42
source/_daily_emails/2025-01-06.md
Normal file
42
source/_daily_emails/2025-01-06.md
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
---
|
||||||
|
title: Actions, Commands or Services?
|
||||||
|
date: 2025-01-06
|
||||||
|
permalink: daily/2025/01/06/actions-commands-services
|
||||||
|
tags:
|
||||||
|
- software-development
|
||||||
|
- drupal
|
||||||
|
- php
|
||||||
|
cta: ~
|
||||||
|
snippet: |
|
||||||
|
To Action or not to Action? I was writing a new class today and wondered whether it should be an Action, Command or Service. Which would you pick?
|
||||||
|
---
|
||||||
|
|
||||||
|
Today I started to write a new class and was trying to decide what to name it and what pattern I wanted to follow.
|
||||||
|
|
||||||
|
Option 1:
|
||||||
|
|
||||||
|
```php
|
||||||
|
class StoreInformationDownloader {
|
||||||
|
|
||||||
|
public function download() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Option 2:
|
||||||
|
|
||||||
|
```php
|
||||||
|
class DownloadStoreInformation {
|
||||||
|
|
||||||
|
public function execute() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Option 1 is a typical Service class.
|
||||||
|
|
||||||
|
Option 2 follows the Command or Action pattern.
|
||||||
|
|
||||||
|
Which would you choose?
|
Loading…
Add table
Add a link
Reference in a new issue