Separating data from function and the Model-View-Controller architecture pattern.

With the basic structure of the application done, and a class made to define the custom question objects we’d be using, the question was raised of how the data would be stored to populate these objects. Each question needs to have stored a sound file, multiple options for users to choose from, and a value to determine which of these is the correct answer. As well as this, a fact needs to be stored relating to each question, however this functionality has not yet been implemented into the application.

So far, the relevant information has simply been stored in the code as an array. This is an array of our custom question objects, and is statically declared in the code before any functionality takes place. This works well for the basic prototype, as it allows the core functionality of the app to work with a small sample of example questions. However, this is not a solution which lends itself well to being easily updated with additional questions in the future. It also doesn’t make understanding this data and where/how it is stored very easy if anyone needs to change the information for any reason.

Both of these issues would be solved by storing the information about all of the questions in the application in a single file, separate from the main body of the code. This  would allow the questions to be updated and changed more easily, since the code of the application itself would not need to be changed at all. The person changing or adding a question could simply open this file, change the text for the relevant question or add a new one, and then drop an accompanying sound file into the right folder within the application directory. This not only makes this process faster to do, but also allows people with no knowledge of the Swift programming language, array declaration, or our custom class structure to add in their own questions or change existing ones without a steep learning curve.

Separating the data from the functionality and appearance of an application in such a way is a common and useful strategy. This way of designing a system is referred to as ‘model-view-controller’ or MVC. As described by Burbeck (1992), “In the MVC paradigm the user input, the modeling of the external world, and the visual feedback to the user are explicitly separated and handled by three types of object, each specialized for its task”. In essence, MVC is made up of a model, which manages the data of the application, a view, which manages graphical/text output, and a controller, which interprets and responds to user inputs and updates the model and view where necessary. In this instance, separating the data for questions into a separate file will create a distinction between the model (this new file) and the controller (the existing ViewController in the Swift code).

To this end, I intend to go about the reworking of the code that has been produced thus far so that these elements can be effectively separated out while still maintaining the intended functionality of the application. This will involve moving the question data to a separate file, and producing some accompanying code in the controller to fetch this data at the right time so that it can be used and displayed in the view. In order for the data to be used within the app, it will likely still be pulled into an array in the code so I expect the implementation of functionality after that point to stay largely the same, however work will need to be done on developing a system to fetch the data and interpret it in the right way. I am not yet certain what form or file-type the data will take, or how exactly the code to manage it will function, but I am certain that completing this task will be beneficial to the general functionality of the application and the ease with which we will be able to continue to work on it.

 

References:

Burbeck, S., 1992. Applications Programming in Smalltalk-80(TM): How to use Model-View-Controller (MVC) [online]. Available from: http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html    [Accessed 15 May 2015].

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s