3
Answers

Abstract Class

Ask a question
gayatri hhhh

gayatri hhhh

13y
1.5k
1

Please help me in understanding the red highligheted area



class
Investor : IInvestor
{
   private string _name;
   private Stock _stock;
   public Investor(string name)
   {
       this._name = name;
   }
   public void Update(Stock stock)
   {
       Console.WriteLine("Notified {0} of {1}'s " +
         "change to {2:C}", _name, stock.Symbol, stock.Price);
   }
 public Stock Stock  (I couldnt understand this piece of code )
   { 
 get { return _stock; }
       set { _stock = value; }
   }
}

interface IInvestor
{
   void Update(Stock stock);
}

abstract class Stock
{
   private string _symbol;
   private double _price;
   private List<IInvestor> _investors = new List<IInvestor>();
   // Constructor
   public Stock(string symbol, double price)
   {
       this._symbol = symbol;
       this._price = price;
   }
   public void Attach(IInvestor investor)
   {
       _investors.Add(investor);
   }
   public void Detach(IInvestor investor)
   {
       _investors.Remove(investor);
   }
   public void Notify()
   {
       foreach (IInvestor investor in _investors)
       {
           investor.Update(this);
       }
       Console.WriteLine("");
   }
   // Gets or sets the price
   public double Price
   {
       get { return _price; }
       set
       {
           if (_price != value)
           {
              _price = value;
               Notify();
           }
       }
   }
   // Gets the symbol
   public string Symbol
   {
       get { return _symbol; }
   }
}




Answers (3)