From 4d4146e197ad227b524a6472d354e4990709fdfc Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Wed, 8 Jan 2025 10:32:47 +0100 Subject: [PATCH] Start Clicker oop --- Emne 3/ClickerOOP/ClickerOOP.sln | 16 ++++++++++++++++ Emne 3/ClickerOOP/ClickerOOP/ClickerOOP.csproj | 10 ++++++++++ Emne 3/ClickerOOP/ClickerOOP/Program.cs | 3 +++ .../DIP.ChatServer/ChatServer.cs | 8 ++++---- .../DIP.ChatServer/IChatClient.cs | 6 ++++++ .../DependencyInversionPrinciple/ChatClient.cs | 3 ++- 6 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 Emne 3/ClickerOOP/ClickerOOP.sln create mode 100644 Emne 3/ClickerOOP/ClickerOOP/ClickerOOP.csproj create mode 100644 Emne 3/ClickerOOP/ClickerOOP/Program.cs create mode 100644 Emne 3/DependencyInversionPrinciple/DIP.ChatServer/IChatClient.cs diff --git a/Emne 3/ClickerOOP/ClickerOOP.sln b/Emne 3/ClickerOOP/ClickerOOP.sln new file mode 100644 index 0000000..7fcf8f7 --- /dev/null +++ b/Emne 3/ClickerOOP/ClickerOOP.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClickerOOP", "ClickerOOP\ClickerOOP.csproj", "{C70D6421-5389-44D4-9ECF-E19B7A6BBAD7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C70D6421-5389-44D4-9ECF-E19B7A6BBAD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C70D6421-5389-44D4-9ECF-E19B7A6BBAD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C70D6421-5389-44D4-9ECF-E19B7A6BBAD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C70D6421-5389-44D4-9ECF-E19B7A6BBAD7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/ClickerOOP/ClickerOOP/ClickerOOP.csproj b/Emne 3/ClickerOOP/ClickerOOP/ClickerOOP.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/ClickerOOP/ClickerOOP/ClickerOOP.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/ClickerOOP/ClickerOOP/Program.cs b/Emne 3/ClickerOOP/ClickerOOP/Program.cs new file mode 100644 index 0000000..e5dff12 --- /dev/null +++ b/Emne 3/ClickerOOP/ClickerOOP/Program.cs @@ -0,0 +1,3 @@ +// See https://aka.ms/new-console-template for more information + +Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/ChatServer.cs b/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/ChatServer.cs index 45ebc40..ed925c6 100644 --- a/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/ChatServer.cs +++ b/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/ChatServer.cs @@ -2,14 +2,14 @@ namespace DIP.ChatServer; public class ChatServer { - private readonly List _clients; + private readonly List _clients; public ChatServer() { - _clients = new List(); + _clients = new List(); } - public void Broadcast(ChatClient client, string message) + public void Broadcast(IChatClient client, string message) { foreach (var chatClient in _clients) { @@ -21,7 +21,7 @@ public class ChatServer } } - public void Register(ChatClient client) + public void Register(IChatClient client) { _clients.Add(client); } diff --git a/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/IChatClient.cs b/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/IChatClient.cs new file mode 100644 index 0000000..fdf1633 --- /dev/null +++ b/Emne 3/DependencyInversionPrinciple/DIP.ChatServer/IChatClient.cs @@ -0,0 +1,6 @@ +namespace DIP.ChatServer; + +public interface IChatClient +{ + void Receive(string message); +} \ No newline at end of file diff --git a/Emne 3/DependencyInversionPrinciple/DependencyInversionPrinciple/ChatClient.cs b/Emne 3/DependencyInversionPrinciple/DependencyInversionPrinciple/ChatClient.cs index ad92640..518f37b 100644 --- a/Emne 3/DependencyInversionPrinciple/DependencyInversionPrinciple/ChatClient.cs +++ b/Emne 3/DependencyInversionPrinciple/DependencyInversionPrinciple/ChatClient.cs @@ -1,6 +1,7 @@ namespace DependencyInversionPrinciple; +using DIP.ChatServer; -public class ChatClient +public class ChatClient : IChatClient { private readonly string _name; private readonly ChatServer _server;