decorator pattern

remotes/origin/master
syneffort 3 years ago
parent 1cfa3c3971
commit 453a0e3302
  1. 6
      DesignPattern/Decorator/App.config
  2. 25
      DesignPattern/Decorator/Circle.cs
  3. 25
      DesignPattern/Decorator/Client.cs
  4. 60
      DesignPattern/Decorator/Decorator.csproj
  5. 24
      DesignPattern/Decorator/FillShapeDecorator.cs
  6. 25
      DesignPattern/Decorator/Program.cs
  7. 36
      DesignPattern/Decorator/Properties/AssemblyInfo.cs
  8. 19
      DesignPattern/Decorator/Shape.cs
  9. 18
      DesignPattern/Decorator/ShapeDecorator.cs
  10. 6
      DesignPattern/DesignPattern.sln

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decorator
{
class Circle : Shape
{
public Circle(Point origin, int radius)
{
X = origin.X;
Y = origin.Y;
Width = radius * 2;
Height = radius * 2;
}
public override void Draw(Graphics g)
{
g.DrawEllipse(Pens.Black, X, Y, Width, Height);
}
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Decorator
{
class Client
{
public static void HowToTest()
{
Form form = new Form();
form.Show();
Graphics gr = form.CreateGraphics();
Shape shape = new Circle(new Point(100, 100), 50);
FillShapeDecorator deco = new FillShapeDecorator(shape);
deco.Draw(gr);
}
}
}

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4BDF9142-7984-485F-AA62-77B7B7359966}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Decorator</RootNamespace>
<AssemblyName>Decorator</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Circle.cs" />
<Compile Include="Client.cs" />
<Compile Include="FillShapeDecorator.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Shape.cs" />
<Compile Include="ShapeDecorator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decorator
{
class FillShapeDecorator : ShapeDecorator
{
public FillShapeDecorator(Shape shape) : base(shape)
{
}
public override void Draw(Graphics g)
{
component.Draw(g);
g.FillEllipse(Brushes.Green, component.X, component.Y, component.Width, component.Height);
}
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decorator
{
/*
* :
* : ,
* ,
*
* ,
*/
class Program
{
static void Main(string[] args)
{
Client.HowToTest();
Console.ReadKey();
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("Decorator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Decorator")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("4bdf9142-7984-485f-aa62-77b7b7359966")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decorator
{
public abstract class Shape
{
public abstract void Draw(Graphics g);
public int X { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decorator
{
public abstract class ShapeDecorator : Shape
{
protected Shape component;
public ShapeDecorator(Shape shape)
{
component = shape;
}
}
}

@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bridge", "Bridge\Bridge.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Composite", "Composite\Composite.csproj", "{52E6E6B5-8A12-4A92-8A38-8697247F4CA2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decorator", "Decorator\Decorator.csproj", "{4BDF9142-7984-485F-AA62-77B7B7359966}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -57,6 +59,10 @@ Global
{52E6E6B5-8A12-4A92-8A38-8697247F4CA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52E6E6B5-8A12-4A92-8A38-8697247F4CA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52E6E6B5-8A12-4A92-8A38-8697247F4CA2}.Release|Any CPU.Build.0 = Release|Any CPU
{4BDF9142-7984-485F-AA62-77B7B7359966}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4BDF9142-7984-485F-AA62-77B7B7359966}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BDF9142-7984-485F-AA62-77B7B7359966}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BDF9142-7984-485F-AA62-77B7B7359966}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save