From 92412bef42d0e5939498d24b128372958726d518 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Tue, 11 Apr 2023 18:40:32 +0300 Subject: [PATCH] Update Lesson 4 Task 2 --- Lesson_4/Task_2/Classes/FireMagic.cs | 6 ++---- Lesson_4/Task_2/Classes/{UnknownMagic.cs => Magic.cs} | 6 +++--- Lesson_4/Task_2/Classes/WaterMagic.cs | 6 ++---- Lesson_4/Task_2/Interfaces/IMagic.cs | 3 ++- Lesson_4/Task_2/Program.cs | 5 ++--- Lesson_4/Task_2/Task_2.csproj | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) rename Lesson_4/Task_2/Classes/{UnknownMagic.cs => Magic.cs} (60%) diff --git a/Lesson_4/Task_2/Classes/FireMagic.cs b/Lesson_4/Task_2/Classes/FireMagic.cs index 3026a2c..6b5de4a 100644 --- a/Lesson_4/Task_2/Classes/FireMagic.cs +++ b/Lesson_4/Task_2/Classes/FireMagic.cs @@ -10,9 +10,7 @@ namespace Open_Closed.Classes { public class FireMagic : IMagic { - public void CountYourMagic() - { - Console.WriteLine("Wow, your magic is fire magic!"); - } + public int MagicValue { get { return 150; } } + public string MagicType { get { return "fire"; } } } } diff --git a/Lesson_4/Task_2/Classes/UnknownMagic.cs b/Lesson_4/Task_2/Classes/Magic.cs similarity index 60% rename from Lesson_4/Task_2/Classes/UnknownMagic.cs rename to Lesson_4/Task_2/Classes/Magic.cs index f94bf1a..c8357a5 100644 --- a/Lesson_4/Task_2/Classes/UnknownMagic.cs +++ b/Lesson_4/Task_2/Classes/Magic.cs @@ -8,11 +8,11 @@ using Open_Closed.Interfaces; namespace Open_Closed.Classes { - public class UnknownMagic : IMagic + public class Magic { - public void CountYourMagic() + public void CountYourMagic(IMagic Magic) { - Console.WriteLine("I understand you..."); + Console.WriteLine($"Your magic is {Magic.MagicType}."); } } } diff --git a/Lesson_4/Task_2/Classes/WaterMagic.cs b/Lesson_4/Task_2/Classes/WaterMagic.cs index e37694a..ef45f6f 100644 --- a/Lesson_4/Task_2/Classes/WaterMagic.cs +++ b/Lesson_4/Task_2/Classes/WaterMagic.cs @@ -10,9 +10,7 @@ namespace Open_Closed.Classes { public class WaterMagic : IMagic { - public void CountYourMagic() - { - Console.WriteLine("Incredible! You have 50 millions of power! It's water magic!"); - } + public int MagicValue { get { return 50000000; } } + 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 6474543..1a2d623 100644 --- a/Lesson_4/Task_2/Interfaces/IMagic.cs +++ b/Lesson_4/Task_2/Interfaces/IMagic.cs @@ -8,6 +8,7 @@ namespace Open_Closed.Interfaces { public interface IMagic { - void CountYourMagic(); + int MagicValue { get; } + string MagicType { get; } } } diff --git a/Lesson_4/Task_2/Program.cs b/Lesson_4/Task_2/Program.cs index 5cd1c52..3177504 100644 --- a/Lesson_4/Task_2/Program.cs +++ b/Lesson_4/Task_2/Program.cs @@ -1,5 +1,4 @@ using Open_Closed.Classes; -(new FireMagic()).CountYourMagic(); -(new WaterMagic()).CountYourMagic(); -(new UnknownMagic()).CountYourMagic(); +(new Magic()).CountYourMagic(new FireMagic()); +(new Magic()).CountYourMagic(new WaterMagic()); diff --git a/Lesson_4/Task_2/Task_2.csproj b/Lesson_4/Task_2/Task_2.csproj index 74abf5c..f02677b 100644 --- a/Lesson_4/Task_2/Task_2.csproj +++ b/Lesson_4/Task_2/Task_2.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 enable enable