Designing Entities with Structs
Learn how to create structs to describe entities.
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 command-line ...