Add Design Patterns
This commit is contained in:
10
ProxyLib/ConcreteSubject.cs
Normal file
10
ProxyLib/ConcreteSubject.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ProxyLib;
|
||||
|
||||
internal class ConcreteSubject: ISubject
|
||||
{
|
||||
|
||||
public void Log()
|
||||
{
|
||||
Console.WriteLine("ConcreteSubject Log");
|
||||
}
|
||||
}
|
||||
6
ProxyLib/ISubject.cs
Normal file
6
ProxyLib/ISubject.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ProxyLib;
|
||||
|
||||
public interface ISubject
|
||||
{
|
||||
void Log();
|
||||
}
|
||||
9
ProxyLib/ProxyLib.csproj
Normal file
9
ProxyLib/ProxyLib.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
13
ProxyLib/SubjectProxy.cs
Normal file
13
ProxyLib/SubjectProxy.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ProxyLib;
|
||||
|
||||
public class SubjectProxy : ISubject
|
||||
{
|
||||
public bool CanLog { get; set; }
|
||||
private readonly ISubject _subject = new ConcreteSubject();
|
||||
|
||||
public void Log()
|
||||
{
|
||||
if (!CanLog) return;
|
||||
_subject.Log();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user