samedi 6 octobre 2018

How do I apply the MVC model to this app?

This question doesn't sound very Stack Overflow related, but I didn't find a better place in the Stack Exchange ecosystem.

I'm super new to Android, Kotlin and mobile apps programming and design, and I wanted to create an app with the following behavior and features.

The App

  1. The app has one activity only: the user clicks anywhere on the screen, something is shown to him/her (e.g., setting a background image, printing some cool message, etc.). The user clicks again, something else happens.
  2. I want this to be very flexible on what it can displayed to the user. Today I want to show awesome images, tomorrow I want be able also to play songs that rock with minimal effort.

The Deisgn - MVC

I started designing this app, and to me seems that the MVC pattern fits pretty well in this scenario, but I'm not sure if I'm applying it correctly to my case as described in this article:

  1. The View is the main activity and the layout. It offers a set of elements that the user can click (a button, a text view, the background, etc.). In addition, it offers many element that can be manipulated by the controller (a text view, the background, media player, etc.). All Android juicy stuff is implemented in the View and the View only.
  2. The Controller is a pure Kotlin class where no Android stuff is present. When the user clicks on the background, it decides what happens. It queries the Model for the next state (i.e., one or more things to show to the user, such as a message, an image, a song file). The controller then decides how to place each element from the state received into View's slots (use that TextView to show this message, use the background to show this image, play this insane song for 5 seconds!).
  3. The Model generates, keeps and provide the state (i.e., things to display to the user). Let's keep things simple in the first version: we have a prefixed set of states, once they've been all returned, let's start over again. All the state elements are stored on the device (I know, it can be space inefficient). But let's keep things flexible: maybe tomorrow I'll make a call to a REST API to get the next state (maybe connect to an S3 bucket, who knows!).

Am I doing this wrong?

Even if the View doesn't interact with the Model, they seem pretty bounded to me: the elements of the state depends on what the View has to offer, on what it can be displayed to the user. What is the meaning to keep a text message in the Model state, if then there is no TextView in the View?

Of course, any feedback is more than appreciated!

Aucun commentaire:

Enregistrer un commentaire