Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这可能是中的C#模型视图控制器控制台应用程序吗?如果不是,原因是什么?_C#_Console_Mvp_Model View Controller - Fatal编程技术网

这可能是中的C#模型视图控制器控制台应用程序吗?如果不是,原因是什么?

这可能是中的C#模型视图控制器控制台应用程序吗?如果不是,原因是什么?,c#,console,mvp,model-view-controller,C#,Console,Mvp,Model View Controller,只是想通过做…来掌握MVC。。。但仍然不确定是否正确 using System; using System.Text; namespace MVPConsoleApp { class Program { static void Main(string[] args) { View objView = new View();

只是想通过做…来掌握MVC。。。但仍然不确定是否正确

    using System;
    using System.Text;

    namespace MVPConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                View objView = new View(); 
                Controller objController = new Controller(objView);
                objController.BuildUi();
                objView.WaitAndRead();

            }


        } //eof Program


        class View
        {

            private string _Prop1Gui  ;
            public string Prop1Gui 
            {
                get { return _Prop1Gui; }
                set { _Prop1Gui = value; } 
            }

            private string _Prop2Gui;
            public string Prop2Gui
            {
                get { return _Prop2Gui; }
                set { _Prop2Gui = value; }
            }

            public void WaitAndRead()
            {

                string bothProps = Console.ReadLine();
                string [] bothStrings = bothProps.Split(new char [] { ' ' } );
                this.Prop1Gui= bothStrings[0];
                this.Prop2Gui = bothStrings[1]  ; 

                Controller objController = new Controller(this);
                objController.StoreData();
                objController.BuildUiAftgerInput();
                this.WaitAndRead();
            }

            public void ShowMsg ( Model objModel) 
            {
                Console.WriteLine("objModel.ModelProp1  " + objModel.ModelProp1 +  
                    " objModel.ModelProp2 " + objModel.ModelProp2);
                Console.WriteLine("Write the new props separated by space !"); 
            }

        } //eof class 

        class Controller
        {
            View View { get; set; }
            Model Model { get; set;  } 


            public Controller(View objView)
            {
                this.View = objView;
                this.LoadData();
             }

            public void BuildUi()
            {
                this.View.ShowMsg(this.Model);
            }

            public void LoadData()
            {
                //get the data from db 
                Model objModel = new Model();
                objModel.ModelProp1 = "ModelProp1";
                objModel.ModelProp2 = "ModelProp2";
                this.Model = objModel;                 
            } //eof LoadData() 

            public void StoreData()
            {
                Model objModel = new Model();
                objModel.ModelProp1 = this.View.Prop1Gui;
                objModel.ModelProp2 = this.View.Prop2Gui;
                this.Model = objModel; 
            }

            public void BuildUiAftgerInput()
            {
                this.View.ShowMsg( this.Model);
            }

        } //eof class 

        class Model
        {
            public string ModelProp1 { get; set; }
            public string ModelProp2 { get; set; } 
        } //eof class 
    } //eof namespace 

简言之,MVC模式应遵循:

  • 视图接收用户输入并将其传递给控制器
  • 控制器根据用户输入更新模型(也可以直接修改视图)
  • 模型将更改通知视图
  • 视图根据对模型的更改自行更新
换句话说,您的视图应该观察您的模型。此时,视图不知道模型何时更改,因此无法相应地更新自身

你应该考虑介绍一些类似的东西