# Do I have to write @impl true before each function?

**URL:** <https://forum.elixirforum.com/t/do-i-have-to-write-impl-true-before-each-function/44036>\
**Category:** Questions\
**Tags:** phoenix\
**Created:** [November 22, 2021, 7:26pm UTC](https://forum.elixirforum.com/t/do-i-have-to-write-impl-true-before-each-function/44036 "2021-11-22T19:26:17Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![tomkonidas](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tomkonidas/32/22982_2.png) [@tomkonidas](https://forum.elixirforum.com/u/tomkonidas)\
**Post date:** [November 22, 2021, 8:11pm UTC](https://forum.elixirforum.com/t/do-i-have-to-write-impl-true-before-each-function/44036/5 "2021-11-22T20:11:16Z")

</div>

So you can define a behaviour and implement it. For example, lets use payment provider.

If we know we will have multiple payment providers (ex: Stripe, Paypal, etc…), we might want a behaviour for payment providers. We can do this with a behaviour.  
We can define the behaviour and say that every module that implements the MyApp.PaymentProvider behaviour needs to implement a `credit/2` and `debit/2` for example.

Now in our own Stripe module we can `@behaviour MyApp.PaymentProvider` and that is saying that we will need to implement the 2 callbacks we defined:

- `debit/2`
- `credit/2`

Now we have a way to make sure we are able to switch between Paypal and Stripe because they follow the same contract. Both `Paypal.credit/2` and `Stripe.credit/2` should take the same args and return the same type/structure.

With Phoenix, they have optional callbacks, You can define your own or use the default. That is why you do not need to implement `Phoenix.LiveComponent.update/2`, but you can impl it if you want.

In your module, if you put one `@impl` over a function, I believe the compiler will complain. Because you iplemented it for another callback but not that specific one, so it thinks you made a possible mistake.

---

_[View the full topic](https://forum.elixirforum.com/t/do-i-have-to-write-impl-true-before-each-function/44036)._
