Skip to content

Commit 38f70e9

Browse files
Merge pull request #2 from mikedegeofroy/lab-3
Lab 3
2 parents b29dda2 + eda62d8 commit 38f70e9

36 files changed

+650
-0
lines changed

Itmo.ObjectOrientedProgramming.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.Tests", "tests\Lab4.Te
2929
EndProject
3030
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab5.Tests", "tests\Lab5.Tests\Lab5.Tests.csproj", "{FA627A62-AD7A-4A72-B15C-EC8AEFD206DB}"
3131
EndProject
32+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3.Console", "src\Lab3.Console\Lab3.Console.csproj", "{9654EFB5-5367-4DAD-8F18-58E113384AA0}"
3233
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lab5", "Lab5", "{99CB5FCA-AC39-4AD0-B4FF-A8C051CC2809}"
3334
EndProject
3435
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{08E62A91-F7B4-4FE8-A1F8-BFD64F7E3A9E}"
@@ -72,6 +73,7 @@ Global
7273
{7E5E46DB-EF55-47E6-822A-6AE20BF2FCD9} = {792FFE57-F1A0-47A4-9E2A-80F75FF2F8DB}
7374
{17689E4A-FE4F-4893-8E28-3BA911DEC8D8} = {792FFE57-F1A0-47A4-9E2A-80F75FF2F8DB}
7475
{FA627A62-AD7A-4A72-B15C-EC8AEFD206DB} = {792FFE57-F1A0-47A4-9E2A-80F75FF2F8DB}
76+
{9654EFB5-5367-4DAD-8F18-58E113384AA0} = {8ED774F4-D429-4B82-B768-50DCA8EFF609}
7577
{99CB5FCA-AC39-4AD0-B4FF-A8C051CC2809} = {8ED774F4-D429-4B82-B768-50DCA8EFF609}
7678
{08E62A91-F7B4-4FE8-A1F8-BFD64F7E3A9E} = {99CB5FCA-AC39-4AD0-B4FF-A8C051CC2809}
7779
{D6F0AF28-4B74-4CEF-BAE0-631C60979762} = {99CB5FCA-AC39-4AD0-B4FF-A8C051CC2809}
@@ -122,6 +124,10 @@ Global
122124
{FA627A62-AD7A-4A72-B15C-EC8AEFD206DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
123125
{FA627A62-AD7A-4A72-B15C-EC8AEFD206DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
124126
{FA627A62-AD7A-4A72-B15C-EC8AEFD206DB}.Release|Any CPU.Build.0 = Release|Any CPU
127+
{9654EFB5-5367-4DAD-8F18-58E113384AA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
128+
{9654EFB5-5367-4DAD-8F18-58E113384AA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
129+
{9654EFB5-5367-4DAD-8F18-58E113384AA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
130+
{9654EFB5-5367-4DAD-8F18-58E113384AA0}.Release|Any CPU.Build.0 = Release|Any CPU
125131
{9BAA271C-E0CC-42C8-83E7-FC398D53874F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
126132
{9BAA271C-E0CC-42C8-83E7-FC398D53874F}.Debug|Any CPU.Build.0 = Debug|Any CPU
127133
{9BAA271C-E0CC-42C8-83E7-FC398D53874F}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/Lab2.Console/Lab2.Console.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

src/Lab2.Console/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


src/Lab3.Console/Lab3.Console.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Lab3\Lab3.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

src/Lab3.Console/Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Drawing;
2+
using Itmo.ObjectOrientedProgramming.Lab3.Decorators;
3+
using Itmo.ObjectOrientedProgramming.Lab3.Display;
4+
using Itmo.ObjectOrientedProgramming.Lab3.Filter;
5+
using Itmo.ObjectOrientedProgramming.Lab3.Logger;
6+
using Itmo.ObjectOrientedProgramming.Lab3.Message;
7+
using Itmo.ObjectOrientedProgramming.Lab3.User;
8+
9+
var message = new Message("Good morning!", "This is a body.", 2);
10+
var user = new User();
11+
var logger = new Logger();
12+
var filter = new PriorityFilter(3);
13+
14+
var proxy2 = new MessageLogger(user, logger);
15+
var proxy1 = new MessageFilter(proxy2, filter);
16+
17+
proxy1.HandleMessage(message);
18+
19+
var display = new DisplayToFile();
20+
21+
display.SetColor(Color.Red);
22+
display.Out("Hello!");

src/Lab3/Decorators/MessageFilter.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Itmo.ObjectOrientedProgramming.Lab3.Filter;
2+
using Itmo.ObjectOrientedProgramming.Lab3.Message;
3+
4+
namespace Itmo.ObjectOrientedProgramming.Lab3.Decorators;
5+
6+
public class MessageFilter : IRecipient
7+
{
8+
private readonly IRecipient _recipient;
9+
private readonly IFilter _filter;
10+
11+
public MessageFilter(IRecipient recipient, IFilter filter)
12+
{
13+
_recipient = recipient;
14+
_filter = filter;
15+
}
16+
17+
public void HandleMessage(IMessage message)
18+
{
19+
if (_filter.Filter(message)) _recipient.HandleMessage(message);
20+
}
21+
}

src/Lab3/Decorators/MessageLogger.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Itmo.ObjectOrientedProgramming.Lab3.Logger;
2+
using Itmo.ObjectOrientedProgramming.Lab3.Message;
3+
4+
namespace Itmo.ObjectOrientedProgramming.Lab3.Decorators;
5+
6+
public class MessageLogger : IRecipient
7+
{
8+
private readonly IRecipient _recipient;
9+
private readonly ILogger _logger;
10+
11+
public MessageLogger(IRecipient recipient, ILogger logger)
12+
{
13+
_recipient = recipient;
14+
_logger = logger;
15+
}
16+
17+
public void HandleMessage(IMessage message)
18+
{
19+
Log(message);
20+
_recipient.HandleMessage(message);
21+
}
22+
23+
private void Log(IRenderable message)
24+
{
25+
_logger.Log(message.Render());
26+
}
27+
}

src/Lab3/Display/Display.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Drawing;
2+
using Itmo.ObjectOrientedProgramming.Lab3.Message;
3+
4+
namespace Itmo.ObjectOrientedProgramming.Lab3.Display;
5+
6+
// TODO
7+
// should have a display that takes in a string.
8+
public class Display : IRecipient
9+
{
10+
private readonly DisplayDriver _displayStrategy;
11+
12+
public Display(IDisplayStrategy displayStrategy)
13+
{
14+
_displayStrategy = new DisplayDriver(displayStrategy);
15+
}
16+
17+
public void HandleMessage(IMessage message)
18+
{
19+
_displayStrategy.OutputText(message.Render(), Color.Red);
20+
}
21+
}

src/Lab3/Display/DisplayDriver.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Drawing;
2+
3+
namespace Itmo.ObjectOrientedProgramming.Lab3.Display;
4+
5+
public class DisplayDriver
6+
{
7+
private readonly IDisplayStrategy _strategy;
8+
9+
public DisplayDriver(IDisplayStrategy strategy)
10+
{
11+
_strategy = strategy;
12+
}
13+
14+
public void OutputText(string text, Color color)
15+
{
16+
_strategy.Clear();
17+
_strategy.SetColor(color);
18+
_strategy.Out(text);
19+
}
20+
}

src/Lab3/Display/DisplayToConsole.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Drawing;
3+
4+
namespace Itmo.ObjectOrientedProgramming.Lab3.Display;
5+
6+
public class DisplayToConsole : IDisplayStrategy
7+
{
8+
private Color _color;
9+
10+
public DisplayToConsole()
11+
{
12+
_color = Color.White;
13+
}
14+
15+
public void Clear()
16+
{
17+
Console.Clear();
18+
}
19+
20+
public void SetColor(Color color)
21+
{
22+
_color = color;
23+
}
24+
25+
public void Out(string text)
26+
{
27+
Console.WriteLine(Crayon.Output.Rgb(_color.R, _color.G, _color.B).Text(text));
28+
}
29+
}

0 commit comments

Comments
 (0)