visitor pattern

remotes/origin/master
syneffort 3 years ago
parent 11cb7eb330
commit 015116a530
  1. 10
      DesignPattern/DesignPattern.sln
  2. 6
      DesignPattern/Visitor/App.config
  3. 18
      DesignPattern/Visitor/Body.cs
  4. 34
      DesignPattern/Visitor/Car.cs
  5. 31
      DesignPattern/Visitor/CarPrintVisitor.cs
  6. 18
      DesignPattern/Visitor/Client.cs
  7. 18
      DesignPattern/Visitor/Engine.cs
  8. 13
      DesignPattern/Visitor/ICarElement.cs
  9. 16
      DesignPattern/Visitor/ICarVisitor.cs
  10. 23
      DesignPattern/Visitor/Program.cs
  11. 36
      DesignPattern/Visitor/Properties/AssemblyInfo.cs
  12. 61
      DesignPattern/Visitor/Visitor.csproj
  13. 18
      DesignPattern/Visitor/Wheel.cs

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32811.315
# Visual Studio Version 16
VisualStudioVersion = 16.0.32630.194
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Singleton", "Singleton\Singleton.csproj", "{37FE4D0C-A213-4EA5-B3EF-DB2DB3971ACE}"
EndProject
@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proxy", "Proxy\Proxy.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iterator", "Iterator\Iterator.csproj", "{FB64AA57-5E45-4DD9-B152-8548CFDD235F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Visitor", "Visitor\Visitor.csproj", "{A34872B5-83A1-4C3C-B20C-24A46DA39E3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -81,6 +83,10 @@ Global
{FB64AA57-5E45-4DD9-B152-8548CFDD235F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB64AA57-5E45-4DD9-B152-8548CFDD235F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB64AA57-5E45-4DD9-B152-8548CFDD235F}.Release|Any CPU.Build.0 = Release|Any CPU
{A34872B5-83A1-4C3C-B20C-24A46DA39E3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A34872B5-83A1-4C3C-B20C-24A46DA39E3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A34872B5-83A1-4C3C-B20C-24A46DA39E3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A34872B5-83A1-4C3C-B20C-24A46DA39E3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

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

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
class Body : ICarElement
{
public string Color => "Siver";
public void Accept(ICarVisitor visitor)
{
visitor.Visit(this);
}
}
}

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
class Car : ICarElement
{
public string Maker => "BMW";
private List<ICarElement> elements;
public Car()
{
elements = new List<ICarElement>
{
new Engine(),
new Body(),
new Wheel()
};
}
public void Accept(ICarVisitor visitor)
{
foreach (ICarElement elem in elements)
{
elem.Accept(visitor);
}
visitor.Visit(this);
}
}
}

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
class CarPrintVisitor : ICarVisitor
{
public void Visit(Engine element)
{
Console.WriteLine(element.Spec);
}
public void Visit(Body element)
{
Console.WriteLine(element.Color);
}
public void Visit(Wheel element)
{
Console.WriteLine(element.Type);
}
public void Visit(Car element)
{
Console.WriteLine(element.Maker);
}
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
class Client
{
public static void HowToTest()
{
ICarElement car = new Car();
ICarVisitor visitor = new CarPrintVisitor();
car.Accept(visitor);
}
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
class Engine : ICarElement
{
public string Spec => "V4";
public void Accept(ICarVisitor visitor)
{
visitor.Visit(this);
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
interface ICarElement
{
void Accept(ICarVisitor visitor);
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
interface ICarVisitor
{
void Visit(Engine element);
void Visit(Body element);
void Visit(Wheel elemetn);
void Visit(Car element);
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
/*
* :
* :
* Visitor
*/
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("Visitor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Visitor")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("a34872b5-83a1-4c3c-b20c-24a46da39e3f")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,61 @@
<?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>{A34872B5-83A1-4C3C-B20C-24A46DA39E3F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Visitor</RootNamespace>
<AssemblyName>Visitor</AssemblyName>
<TargetFrameworkVersion>v4.8.1</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.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="Body.cs" />
<Compile Include="Car.cs" />
<Compile Include="CarPrintVisitor.cs" />
<Compile Include="Client.cs" />
<Compile Include="Engine.cs" />
<Compile Include="ICarElement.cs" />
<Compile Include="ICarVisitor.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Wheel.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Visitor
{
class Wheel : ICarElement
{
public string Type => "P26";
public void Accept(ICarVisitor visitor)
{
visitor.Visit(this);
}
}
}
Loading…
Cancel
Save