DEV Community

Robson TenĂłrio
Robson TenĂłrio

Posted on

Our way: Actions vs Services

👉 Go to Summary

There is no wrong or right way, there is our way.

-- Someone

.
.
.

Actions

  1. It represents an internal app use case.
  2. Each action must contain one use case.
  3. Naming is important.
  4. An action can call another action or service in complex scenarios.

class MakeUserAvatarAction {

    function __construct(){ 
        // ... 
    }

    function execute(){
        // It does only 1 thing
    }    
}

Enter fullscreen mode Exit fullscreen mode

Services

  1. It represents external integrations, commonly through API.
  2. You can have many methods.
class KeycloakService{

    function __construct(){ 
        // ... 
    }

    function createUser() { }

    function syncRoles() { }

    ...
}
Enter fullscreen mode Exit fullscreen mode

Actions vs Services

  1. An action has one method, that solves one internal use case.
  2. An service can have more methods, that represents an external integration.
app/
    |
    |__ Actions/    
    |   |   
    |   |__ post/
    |   |   |
    |   |   |__ DeletePostAction.php
    |   |   |__ PromotePostAction.php
    |   |
    |   |__ users/
    |       |
    |       |__ MakeAvatarAction.php
    |
    |__ Services/
        |
        |__ PaymentService.php
        |__ KeycloackService.php

Enter fullscreen mode Exit fullscreen mode

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay