Commencing Our Quizzes

Let’s start adding functions to our responses, templates, and questions.

Responses

Let’s start with a simple example. Nothing in Mastery is more straightforward than a Response. You might wonder how large a module has to be. The answer is as big as it needs to be to do a single job. On a module basis, we want to keep the external API simple and internal details hidden. That way, the interactions between modules will be simpler. In a sense, we’re building layers inside of layers.

Some of our modules have only data and a constructor, and that’s fine. Responses exist only to be data-holding structs, so all we need is a constructor. Think of a constructor as a convenience function to instantiate a piece of data. We’ll add our constructor to /lib/mastery/core/response.ex, like this:

Get hands-on with 1200+ tech skills courses.