From 4df251331da7270d09c7fdf538b3db2e1ba0ef5a Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sat, 15 Apr 2023 23:25:41 +0300 Subject: [PATCH] Update Lesson 4 Task 2 --- Lesson_4/Task_2/Classes/FireMagic.cs | 6 +++--- Lesson_4/Task_2/Classes/Magic.cs | 7 +++++-- Lesson_4/Task_2/Classes/WaterMagic.cs | 6 +++--- Lesson_4/Task_2/Interfaces/IMagic.cs | 5 ++++- Lesson_4/Task_2/Interfaces/IMagicClass.cs | 14 -------------- Lesson_4/Task_2/Program.cs | 4 ++-- 6 files changed, 17 insertions(+), 25 deletions(-) delete mode 100644 Lesson_4/Task_2/Interfaces/IMagicClass.cs diff --git a/Lesson_4/Task_2/Classes/FireMagic.cs b/Lesson_4/Task_2/Classes/FireMagic.cs index 8842b59..c10a691 100644 --- a/Lesson_4/Task_2/Classes/FireMagic.cs +++ b/Lesson_4/Task_2/Classes/FireMagic.cs @@ -8,9 +8,9 @@ using Open_Closed.Interfaces; namespace Open_Closed.Classes { - public class FireMagic : IMagicClass + public class FireMagic : Magic, IMagic { - public int MagicValue { get { return 150; } } - public string MagicType { get { return "fire"; } } + public override int MagicValue { get { return 150; } } + public override string MagicType { get { return "fire"; } } } } diff --git a/Lesson_4/Task_2/Classes/Magic.cs b/Lesson_4/Task_2/Classes/Magic.cs index 2bb046f..fac03fc 100644 --- a/Lesson_4/Task_2/Classes/Magic.cs +++ b/Lesson_4/Task_2/Classes/Magic.cs @@ -8,9 +8,12 @@ using Open_Closed.Interfaces; namespace Open_Closed.Classes { - public class Magic : IMagic + abstract public class Magic : IMagic { - public void CountYourMagic(string MagicType) + abstract public int MagicValue { get; } + abstract public string MagicType { get; } + + public void CountYourMagic() { Console.WriteLine($"Your magic is {MagicType}."); } diff --git a/Lesson_4/Task_2/Classes/WaterMagic.cs b/Lesson_4/Task_2/Classes/WaterMagic.cs index aef7e32..6544e2b 100644 --- a/Lesson_4/Task_2/Classes/WaterMagic.cs +++ b/Lesson_4/Task_2/Classes/WaterMagic.cs @@ -8,9 +8,9 @@ using Open_Closed.Interfaces; namespace Open_Closed.Classes { - public class WaterMagic : IMagicClass + public class WaterMagic : Magic, IMagic { - public int MagicValue { get { return 50000000; } } - public string MagicType { get { return "water"; } } + public override int MagicValue { get { return 50000000; } } + public override string MagicType { get { return "water"; } } } } diff --git a/Lesson_4/Task_2/Interfaces/IMagic.cs b/Lesson_4/Task_2/Interfaces/IMagic.cs index d2599f7..ac64d46 100644 --- a/Lesson_4/Task_2/Interfaces/IMagic.cs +++ b/Lesson_4/Task_2/Interfaces/IMagic.cs @@ -8,6 +8,9 @@ namespace Open_Closed.Interfaces { public interface IMagic { - void CountYourMagic(string MagicType); + abstract int MagicValue { get; } + abstract string MagicType { get; } + + void CountYourMagic(); } } diff --git a/Lesson_4/Task_2/Interfaces/IMagicClass.cs b/Lesson_4/Task_2/Interfaces/IMagicClass.cs deleted file mode 100644 index 7a44e78..0000000 --- a/Lesson_4/Task_2/Interfaces/IMagicClass.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Open_Closed.Interfaces -{ - public interface IMagicClass - { - int MagicValue { get; } - string MagicType { get; } - } -} diff --git a/Lesson_4/Task_2/Program.cs b/Lesson_4/Task_2/Program.cs index 207c754..1f2dfcb 100644 --- a/Lesson_4/Task_2/Program.cs +++ b/Lesson_4/Task_2/Program.cs @@ -1,4 +1,4 @@ using Open_Closed.Classes; -(new Magic()).CountYourMagic(new FireMagic().MagicType); -(new Magic()).CountYourMagic(new WaterMagic().MagicType); +(new FireMagic()).CountYourMagic(); +(new WaterMagic()).CountYourMagic();