Skip to content

Commit

Permalink
Clarify primitive obsession
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 26, 2023
1 parent e88377f commit b86b8ba
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/elixir/pages/anti-patterns/design-anti-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ This refactoring is only possible when you own both modules. If the module you a

#### Problem

This anti-pattern happens when Elixir basic types (for example, *integer*, *float*, and *string*) are abusively used in function parameters and code variables, rather than creating specific composite data types (for example, *tuples* and *structs*) that can better represent a domain.
This anti-pattern happens when Elixir basic types (for example, *integer*, *float*, and *string*) are abusively used in function parameters and code variables, rather than creating specific composite data types (for example, *tuples*, *maps*, and *structs*) that can better represent a domain.

#### Example

Expand All @@ -260,7 +260,7 @@ Another example of this anti-pattern is using floating numbers to model money an

#### Refactoring

We can create an `Address` struct to remove this anti-pattern, better representing this domain through a composite type. Additionally, we can modify the `process_address/1` function to accept a parameter of type `Address` instead of a *string*. With this modification, we can extract each field of this composite type individually when needed.
Possible solutions to this anti-pattern is to use maps or structs to model our address. The example below creates an `Address` struct, better representing this domain through a composite type. Additionally, we can modify the `process_address/1` function to accept a parameter of type `Address` instead of a *string*. With this modification, we can extract each field of this composite type individually when needed.

```elixir
defmodule Address do
Expand Down

0 comments on commit b86b8ba

Please sign in to comment.