Designing Entities with Structs
Explore how to design and create structs in Elixir to represent domain entities within an application. Understand how to define attributes, initialize structs, and organize your codebase by separating domain logic from user interface code. Practice using Mix and IEx to compile and test your structs for consistent application data management.
We'll cover the following...
Programming language entities and data types are not enough when we’re building a larger application. We need to create new data entities to express the application domain. In Elixir, we employ structs. We covered how to use them in the lesson Unpacking Values from Lists, Maps, and Structs, in Chapter 4, but now we’ll see how to create them.
We’ll create a struct that represents the player’s hero. Then we’ll organize our application, separating the domain entities from CLI code by listing the heroes’ options to the player. Then we’ll use some Mix ...