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); }
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); }
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; }
public void Comfort(Baby b) { Console.WriteLine($"{Name} comforts {b.Name}"); if (!_isExhausted) { _isExhausted = true; } else { b.RemoveComforter(Comfort); } }
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; } }
public void EscapeToMexico(Baby b) { b.RemoveComforter(EscapeToMexico); Console.WriteLine($"{Name} escapes to Mexico!"); }
public void Comfort(Baby b) { Console.WriteLine($"{Name} gives a caress to the {b.Name}"); }
public void EscapeToMexico(Baby b) { Console.WriteLine($"{Name} escapes to Mexico!"); b.Cries -= EscapeToMexico; }
public void Comfort(Baby b) { Console.WriteLine($"Mum {Name} comforts Baby {b.Name}"); }
public void EscapeToMexico(Baby b) { // ? how can I do this? }