Dagen slutt
This commit is contained in:
parent
8dfac53540
commit
6361e14b88
6 changed files with 37 additions and 2 deletions
|
@ -1,28 +0,0 @@
|
|||
namespace DependencyInversionPrinciple;
|
||||
|
||||
public class ChatServer
|
||||
{
|
||||
private readonly List<ChatClient> _clients;
|
||||
|
||||
public ChatServer()
|
||||
{
|
||||
_clients = new List<ChatClient>();
|
||||
}
|
||||
|
||||
public void Broadcast(ChatClient client, string message)
|
||||
{
|
||||
foreach (var chatClient in _clients)
|
||||
{
|
||||
if (chatClient != client)
|
||||
{
|
||||
chatClient.Receive(message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Register(ChatClient client)
|
||||
{
|
||||
_clients.Add(client);
|
||||
}
|
||||
}
|
|
@ -7,4 +7,8 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DIP.ChatServer\DIP.ChatServer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
using DependencyInversionPrinciple;
|
||||
using DIP.ChatServer;
|
||||
|
||||
var server = new ChatServer();
|
||||
|
||||
var client1 = new ChatClient("Per", server);
|
||||
var client2 = new ChatClient("Knut", server);
|
||||
var client3 = new ChatClient("Espen", server);
|
||||
|
||||
client1.Say("Hello");
|
||||
client2.Say("Hello");
|
||||
client3.Say("Hello");
|
||||
|
||||
client1.Say("Hello");
|
Loading…
Add table
Add a link
Reference in a new issue