Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace GOFObserver
- {
- abstract class Taqueria{
- private string _nombre;
- private double _price;
- private List<Ihambriento> _bandahambrientos = new List<Ihambriento>();
- //constructor
- public Taqueria(string name, double price) {
- this. _nombre = name;
- this. _price = price;
- }
- public void Attach(Ihambriento hambriento)
- {
- _bandahambrientos.Add(hambriento);
- }
- public void Detach(Ihambriento hambriento) {
- _bandahambrientos.Remove(hambriento);
- }
- public void NotifyPrecio()
- {
- foreach (Ihambriento hambriento in _bandahambrientos)
- {
- hambriento.checarmonedas(this);
- }
- }
- public double Price{
- get{return _price;}
- set {
- if (_price != value) {
- _price = value;
- NotifyPrecio();
- }
- }
- }
- }
- class Chema : Taqueria {
- public Chema(string name, double price): base(name,price){}
- }
- interface Ihambriento {
- void checarmonedas(Taqueria taqueria);
- }
- class Musicos: Ihambriento {
- private string _nombre;
- private Taqueria _tacos;
- public Musicos( string name) {
- _nombre = name;
- }
- public void checarmonedas(Taqueria taqueria)
- {
- Console.WriteLine("Soy: "+ _nombre + " y Checo monedas, porque los tacos estan a: {0}", taqueria.Price);
- }
- public Taqueria Taqueria
- {
- get { return _tacos; }
- set { _tacos = value; }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Chema chemita = new Chema("gringas", 12.5);
- chemita.Attach(new Musicos("zepeda"));
- chemita.Attach(new Musicos("sergio"));
- chemita.Attach(new Musicos("pablo"));
- Console.WriteLine("los tacos estan a 14");
- chemita.Price = 14;
- Console.WriteLine("los tacos estan a 7");
- chemita.Price = 7;
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement