Advertisement
Guest User

Events- Taqueria

a guest
Jul 25th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace GOFObserver
  7. {
  8.  
  9.    abstract class Taqueria{
  10.  
  11.        private string _nombre;
  12.        private double _price;
  13.        private List<Ihambriento> _bandahambrientos = new List<Ihambriento>();
  14.  
  15.  
  16.        //constructor
  17.  
  18.        public Taqueria(string name, double price) {
  19.           this. _nombre = name;
  20.           this. _price = price;
  21.        
  22.        }
  23.  
  24.        public void Attach(Ihambriento hambriento)
  25.        {
  26.  
  27.            _bandahambrientos.Add(hambriento);
  28.        }
  29.  
  30.        public void Detach(Ihambriento hambriento) {
  31.  
  32.            _bandahambrientos.Remove(hambriento);
  33.        
  34.        }
  35.  
  36.        public void NotifyPrecio()
  37.        {
  38.  
  39.            foreach (Ihambriento hambriento in _bandahambrientos)
  40.            {
  41.                hambriento.checarmonedas(this);
  42.            }
  43.            
  44.         }
  45.        
  46.        public double Price{
  47.             get{return _price;}
  48.            set {
  49.                
  50.                if (_price != value) {
  51.  
  52.                    _price = value;
  53.                    NotifyPrecio();
  54.                }
  55.            
  56.            
  57.            }
  58.        
  59.        }
  60.  
  61.    
  62.    }
  63.  
  64.  
  65.  
  66.     class Chema : Taqueria {
  67.  
  68.        public Chema(string name, double price): base(name,price){}
  69.  
  70.  
  71.  
  72.    
  73.    
  74.    }
  75.  
  76.     interface Ihambriento {
  77.         void checarmonedas(Taqueria taqueria);
  78.    
  79.     }
  80.  
  81.     class Musicos: Ihambriento {
  82.  
  83.         private string _nombre;
  84.         private Taqueria _tacos;
  85.  
  86.  
  87.         public Musicos( string name) {
  88.  
  89.             _nombre = name;
  90.         }
  91.  
  92.         public void checarmonedas(Taqueria taqueria)
  93.         {
  94.  
  95.             Console.WriteLine("Soy: "+  _nombre  + " y Checo monedas, porque los tacos estan a: {0}", taqueria.Price);
  96.  
  97.         }
  98.  
  99.  
  100.         public Taqueria Taqueria
  101.         {
  102.  
  103.             get { return _tacos; }
  104.             set { _tacos = value; }
  105.         }
  106.    
  107.    
  108.     }
  109.  
  110.  
  111.  
  112.  
  113.     class Program
  114.     {
  115.         static void Main(string[] args)
  116.         {
  117.             Chema chemita = new Chema("gringas", 12.5);
  118.             chemita.Attach(new Musicos("zepeda"));
  119.             chemita.Attach(new Musicos("sergio"));
  120.             chemita.Attach(new Musicos("pablo"));
  121.  
  122.             Console.WriteLine("los tacos estan a 14");
  123.             chemita.Price = 14;
  124.  
  125.  
  126.             Console.WriteLine("los tacos estan a 7");
  127.             chemita.Price = 7;
  128.  
  129.  
  130.             Console.ReadKey();
  131.  
  132.  
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement