vendredi 1 avril 2016

MVC design pattern for multiplatform lib

I currently have a design problem currently on a personal project, I'm developing both an Android app (using xamarin) and a C# wpf windows application.

The application on desktop help the user to design some exercices that the student on the android app can practice. But currently, I want to have a good structure for the code, by principally having a common lib to both apps. The problem is, following the MVC design pattern, everything in my model should be independent from the view. Or, on Android I need to keep track when an exercise is running, and what button the student pressed. Or this kind of information is not saved after the exercise is done, and from the windows app point of view it's useless information. So in this case should I write a kind of wrapper around my model for the android app so I can save this data ? It seems that doing this way is going against the MVC pattern, but I can't find a solution to this. To better illustrate my problem here is my model :

public class File
{
    public string Name { get; set; } = "file";
    public List<Module> Modules { get; set; } = new List<Module>();
}

public class Module
{
    public string Title { get; set; } = string.Empty;
    public string Color { get; set; } = "0xFF0000";
    public List<Exercice> Exercices { get; set; } = new List<Exercice>();
}

public class Exercice
{
    public string Name { get; set; } = string.Empty;
    public List<string> Sounds { get; set; } = new List<string>();
    public List<Unit> Units { get; set; } = new List<Unit>();
    public bool Randomize { get; set; } = false;
}

public class Unit
{
    public string Text { get; set; } = string.Empty;
    public List<string> Sounds { get; set; } = new List<string>();
    public EType Type { get; set; }
    public bool Solution { get; set; } = true;
    public List<UnitChild> Units { get; set; } = new List<UnitChild>();
}

public class UnitChild
{
    public string Text { get; set; } = string.Empty;
    public List<string> Sounds { get; set; } = new List<string>();
    public EType Type { get; set; }
    public bool Solution { get; set; } = true;
}

public enum EType
{
    Touch,
    Display,
    Voice
}

Everything is loaded and parsed from a YAML file, because I need this to be really structured.

In each of this class, I don't want to keep (in Unit and UnitChild classes) which one has been pressed, because it's superfluous and maybe need to be saved in the controller (which I currently didn't wrote, since I want to figure this out before the actual coding). Basically, all the fields are the core of the exercices, and is the only data needed for the Windows app.

Thanks for your help !

I hope this does not look messy

Aucun commentaire:

Enregistrer un commentaire