Exemple #1
0
 public void MakeBaby(Dad d, string babyName)
 {
     Console.WriteLine($"Mum {Name} made a Baby with Dad {d.Name}");
     Child = new Baby(babyName);
     Child.AddComforter(this);
     Child.AddComforter(d);
 }
Exemple #2
0
 public void MakeBaby(Dad d, string babyName)
 {
     Console.WriteLine($"{Name} made a Baby with {d.Name}");
     Child = new Baby(babyName);
     Child.AddComforter(Comfort);
     Child.AddComforter(d.EscapeToMexico);
 }
Exemple #3
0
 public void MakeBaby(Dad d, string babyName)
 {
     Console.WriteLine($"{Name} made a Baby with {d.Name}");
     Child = new Baby(babyName);
     // Ad un evento posso associare metodi con l'operatore +=.
     // Quindi quando l'evento viene invocato,
     // i metodi "agganciati" vengono chiamati. In ordine.
     Child.Cries += Comfort;
     Child.Cries += d.EscapeToMexico;
 }
Exemple #4
0
        public void Comfort(Baby b)
        {
            Console.WriteLine($"{Name} comforts {b.Name}");

            if (!_isExhausted)
            {
                _isExhausted = true;
            }
            else
            {
                b.RemoveComforter(Comfort);
            }
        }
Exemple #5
0
        public void Comfort(Baby b)
        {
            Console.WriteLine($"{Name} comforts {b.Name}");

            if (!_isExhausted)
            {
                _isExhausted = true;
            }
            else
            {
                // Posso rimuovere metodi da un evento, con l'operatore -=
                b.Cries -= Comfort;
            }
        }
Exemple #6
0
        public void EscapeToMexico(Baby b)
        {
            b.RemoveComforter(EscapeToMexico);

            Console.WriteLine($"{Name} escapes to Mexico!");
        }
Exemple #7
0
 public void Comfort(Baby b)
 {
     Console.WriteLine($"{Name} gives a caress to the {b.Name}");
 }
Exemple #8
0
        public void EscapeToMexico(Baby b)
        {
            Console.WriteLine($"{Name} escapes to Mexico!");

            b.Cries -= EscapeToMexico;
        }
Exemple #9
0
 public void Comfort(Baby b)
 {
     Console.WriteLine($"Mum {Name} comforts Baby {b.Name}");
 }
Exemple #10
0
 public void EscapeToMexico(Baby b)
 {
     // ? how can I do this?
 }