Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide authored Sep 22, 2023
1 parent 8031cc3 commit 563cc06
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/elixir/pages/anti-patterns/design-anti-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,16 @@ In the following code, all the data used in the `calculate_total_item/1` functio

```elixir
defmodule Order do
def calculate_total_order(list_items) do
...
end
# Some functions...

def calculate_total_item(id) do
item = OrderItem.find_item(id)
total = (item.price + item.taxes) * item.amount
discount = OrderItem.find_discount(item)

unless is_nil(discount) do # <= all data comes from OrderItem!
total - total * discount
else
total
end
if discount = OrderItem.find_discount(item) do
total - total * discount
else
total
end
end
end
```
Expand All @@ -254,9 +250,7 @@ To remove this anti-pattern we can move `calculate_total_item/1` to `OrderItem`.

```elixir
defmodule Order do
def calculate_total_order(list_items) do
...
end
# Some functions...
end
```

Expand Down

0 comments on commit 563cc06

Please sign in to comment.