using System; namespace JmennyProstor { class Program { public static void Main(string[] args) { Trida trida = new Trida("ahoj", new ImplementaceNecehoA()); try { trida.VykonnaMetoda(); } catch (InvalidOperationException e) { Console.WriteLine("Exception caught"); } trida.Polozka = 1; trida.VykonnaMetoda(); trida = new Trida(2, "nazdar", new ImplementaceNecehoB()); trida.VykonnaMetoda(); } } public interface Rozhrani { string Neco(); } public class Trida { private Rozhrani necoService; public Trida() { } public Trida(string retezec, Rozhrani neco) { this.Retezec = retezec; this.necoService = neco; } public Trida(int polozka, string retezec, Rozhrani neco) { this.polozka = polozka; this.Retezec = retezec; this.necoService = neco; } public void Metoda() { return; } private int polozka; public int Polozka { get { return polozka; } set { if (value > 0) polozka = value; } } public string Retezec { get; private set; } public void VykonnaMetoda() { if (polozka == 0) throw new InvalidOperationException("Polozka is not properly set."); Console.WriteLine("Vykonavam ve stavu {0}, {1} za pomoci {2}", polozka, Retezec, necoService.Neco()); } } public class Trida2 : Trida { public override void Metoda() { return; } } public class ImplementaceNecehoA : Rozhrani { public string Neco() { return "A"; } } public class ImplementaceNecehoB : Rozhrani { public string Neco() { return "B"; } } }