---
title: Use service objects for complex business logic
impact: HIGH
impactDescription: Improve code organization and testability.
tags: rails, architecture, service-objects, patterns
---

## Use service objects for complex business logic

Improve code organization and testability. Extract complex business logic (payments, onboarding, multi-step processes) into service objects. Service objects should have a single public method (e.g., `call`, `execute`) and reside in `app/services/`.

**Incorrect (Logic inside model):**

```ruby
class Payment < ApplicationRecord
  def process!
    # API calls, state changes, email triggers...
  end
end
```

**Correct (Decoupled Service):**

```ruby
class PaymentProcessor
  def initialize(payment)
    @payment = payment
  end

  def call
    # API calls, state changes, email triggers...
  end
end
```

**Tools:** Custom linter, Manual Review
