Csharp/CSharp Tutorial/Design Patterns/MVC Pattern

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

MVC Patterns

<source lang="csharp">using System; using System.Collections.Generic; using System.Text;

   interface IController
   {
      void DisplayPrice();
   }
   public class Model
   {
       public double Price()
       {
           return 100;
       }
   }
   public class FirstController: IController
   {
     private Model mod;
     public void DisplayPrice()
     {
       double cost = mod.Price() * 1.15;
       String message = "first USD " + cost.ToString();
       Console.WriteLine(message);
     }
     public FirstController()
     {
       mod = new Model();
     }
   }    
   public class SecondController: IController
   {
     private Model mod;

     public void DisplayPrice()
     {
           double cost = mod.Price()*1.1;
           String message = "second USD " + cost.ToString();
           Console.WriteLine(message);
     }
     public SecondController()
     {
       mod = new Model();
     }
   }
   public class Client
   {
       static void Main(string[] args)
       {
         SecondController viewUS = new SecondController();
         viewUS.DisplayPrice();
         FirstController viewNorway = new FirstController();
         viewNorway.DisplayPrice();
       }
   }</source>