From b64a9ea7b9360878962c4db19f051adfe6a42eda Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 16 Apr 2023 15:30:25 +0300 Subject: [PATCH] Update Lesson 4 Task 2 --- Lesson_4/Task_2/Classes/FireMagic.cs | 5 ++--- Lesson_4/Task_2/Classes/Magic.cs | 21 --------------------- Lesson_4/Task_2/Classes/WaterMagic.cs | 5 ++--- Lesson_4/Task_2/Interfaces/IMagic.cs | 8 +++++--- Lesson_4/Task_2/Program.cs | 5 +++-- 5 files changed, 12 insertions(+), 32 deletions(-) delete mode 100644 Lesson_4/Task_2/Classes/Magic.cs diff --git a/Lesson_4/Task_2/Classes/FireMagic.cs b/Lesson_4/Task_2/Classes/FireMagic.cs index c10a691..30ecab7 100644 --- a/Lesson_4/Task_2/Classes/FireMagic.cs +++ b/Lesson_4/Task_2/Classes/FireMagic.cs @@ -8,9 +8,8 @@ using Open_Closed.Interfaces; namespace Open_Closed.Classes { - public class FireMagic : Magic, IMagic + public class FireMagic : IMagic { - public override int MagicValue { get { return 150; } } - public override string MagicType { get { return "fire"; } } + public string MagicType { get { return "fire"; } } } } diff --git a/Lesson_4/Task_2/Classes/Magic.cs b/Lesson_4/Task_2/Classes/Magic.cs deleted file mode 100644 index 7dcc18b..0000000 --- a/Lesson_4/Task_2/Classes/Magic.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Open_Closed.Interfaces; - -namespace Open_Closed.Classes -{ - public abstract class Magic : IMagic - { - public abstract int MagicValue { get; } - public abstract 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 6544e2b..dc1e6f9 100644 --- a/Lesson_4/Task_2/Classes/WaterMagic.cs +++ b/Lesson_4/Task_2/Classes/WaterMagic.cs @@ -8,9 +8,8 @@ using Open_Closed.Interfaces; namespace Open_Closed.Classes { - public class WaterMagic : Magic, IMagic + public class WaterMagic : IMagic { - public override int MagicValue { get { return 50000000; } } - public override string MagicType { get { return "water"; } } + public string MagicType { get { return "water"; } } } } diff --git a/Lesson_4/Task_2/Interfaces/IMagic.cs b/Lesson_4/Task_2/Interfaces/IMagic.cs index ac64d46..2c6e708 100644 --- a/Lesson_4/Task_2/Interfaces/IMagic.cs +++ b/Lesson_4/Task_2/Interfaces/IMagic.cs @@ -8,9 +8,11 @@ namespace Open_Closed.Interfaces { public interface IMagic { - abstract int MagicValue { get; } - abstract string MagicType { get; } + string MagicType { get; } - void CountYourMagic(); + public void CountYourMagic() + { + Console.WriteLine($"Your magic is {MagicType}."); + } } } diff --git a/Lesson_4/Task_2/Program.cs b/Lesson_4/Task_2/Program.cs index 1f2dfcb..99982e5 100644 --- a/Lesson_4/Task_2/Program.cs +++ b/Lesson_4/Task_2/Program.cs @@ -1,4 +1,5 @@ using Open_Closed.Classes; +using Open_Closed.Interfaces; -(new FireMagic()).CountYourMagic(); -(new WaterMagic()).CountYourMagic(); +((IMagic) new FireMagic()).CountYourMagic(); +((IMagic) new WaterMagic()).CountYourMagic();