# The Module Behind the Curtain

Use `defdelegate` when a function should simply forward its arguments to another module.

```elixir
defmodule Users do
  defdelegate get(id), to: Accounts
end
```

This is equivalent to writing:

```elixir
defmodule Users do
  def get(id), do: Accounts.get(id)
end
```

`defdelegate` is useful when you want to expose a function through a public API without duplicating its implementation.

You can also rename the delegated function:

```elixir
defmodule User do
  defdelegate find_user(id), to: Accounts, as: :get
end
```

This calls `Accounts.get(id)` when `Users.find_user(id)` is invoked.

A good rule of thumb: use `defdelegate` when the function exists purely as a forwarding layer; if you need additional logic, define the function normally.


---

Created by: spapiernik
Date: September 01, 2026
URL: https://elixirdrops.net/d/d8T1X4sN
