我目前在个人项目上遇到设计问题,我正在开发Android应用程序(使用xamarin)和C#wpf windows应用程序。
桌面上的应用程序可帮助用户设计Android应用程序上的学生可以练习的一些练习。但是目前,我希望代码具有良好的结构,主要是为这两个应用程序提供一个通用的lib。问题是,遵循MVC设计模式,我的模型中的所有内容都应该独立于视图。或者,在Android上我需要跟踪运动时的运行情况,以及学生按下的按钮。或者在练习完成后不保存这种信息,从windows app的角度来看它是无用的信息。所以在这种情况下我应该为我的Android应用程序模型编写一种包装器,以便保存这些数据吗?看起来这样做违背了MVC模式,但我无法找到解决方案。为了更好地说明我的问题,我的模型是:
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
}
所有内容都是从YAML文件中加载和解析的,因为我需要这样做才能真正构建。
在这个类中,我不想保留(在Unit和UnitChild类中)哪个被按下,因为它是多余的,可能需要保存在控制器中(我目前没有写,因为我想在实际编码之前弄清楚这一点)。基本上,所有字段都是练习的核心,并且是Windows应用程序所需的唯一数据。
感谢您的帮助!
我希望这看起来并不凌乱
答案 0 :(得分:0)
我自己想出来了,
阅读有关MVC设计模式的文档,以及有关C#WPF编程的更具体的文章。
如果你处在我的情况下,你需要做的是保持你的模型干净,只保留两个应用程序中的共享变量,以及控制器中的应用程序特定变量,因为他是在视图和模型。