---
title: Use Composition and Concerns over Deep Inheritance
impact: MEDIUM
impactDescription: avoids fragile base classes and promotes reusable logic
tags: architecture, inheritance, composition, rails-concerns, quality
---

## Use Composition and Concerns over Deep Inheritance

Avoid deep class hierarchies. In Rails, use `ActiveSupport::Concern` to extract shared behavior into modules that can be included in multiple classes.

**Incorrect (deep inheritance):**

```ruby
class BaseUser < ActiveRecord::Base; end
class StaffUser < BaseUser; end
class AdminUser < StaffUser; end # Too deep, fragile
```

**Correct (using concerns):**

```ruby
# app/models/concerns/authenticatable.rb
module Authenticatable
  extend ActiveSupport::Concern
  
  included do
    validates :email, presence: true
  end
end

class User < ApplicationRecord
  include Authenticatable
end
```

**Tools:** RuboCop
---
