Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e5e140a

Browse files
author
anupavanm
committed
initial solution, Factory pattern example
1 parent 91e3999 commit e5e140a

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

‎DesignPatterns.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27004.2009
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern", "FactoryPattern\FactoryPattern.csproj", "{EC684E1B-EA3F-47FD-8F45-175C56667F13}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EC684E1B-EA3F-47FD-8F45-175C56667F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EC684E1B-EA3F-47FD-8F45-175C56667F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EC684E1B-EA3F-47FD-8F45-175C56667F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EC684E1B-EA3F-47FD-8F45-175C56667F13}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1F186729-EAD1-4045-8DAF-5C914B4D4824}
24+
EndGlobalSection
25+
EndGlobal

‎FactoryPattern/FactoryPattern.csproj

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

‎FactoryPattern/Program.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
3+
namespace FactoryPattern
4+
{
5+
public interface IDoor
6+
{
7+
int GetHeight();
8+
int GetWidth();
9+
}
10+
11+
public class WoodenDoor : IDoor
12+
{
13+
private int Height { get; set; }
14+
private int Width { get; set; }
15+
16+
public WoodenDoor(int height, int width)
17+
{
18+
this.Height = height;
19+
this.Width = width;
20+
}
21+
22+
public int GetHeight()
23+
{
24+
return this.Height;
25+
}
26+
public int GetWidth()
27+
{
28+
return this.Width;
29+
}
30+
}
31+
32+
public static class DoorFactory
33+
{
34+
public static IDoor MakeDoor(int height, int width)
35+
{
36+
return new WoodenDoor(height, width);
37+
}
38+
}
39+
class Program
40+
{
41+
static void Main(string[] args)
42+
{
43+
var door = DoorFactory.MakeDoor(80, 30);
44+
Console.WriteLine("Height of Door : {0}", door.GetHeight());
45+
Console.WriteLine("Width of Door : {0}", door.GetWidth());
46+
Console.ReadLine();
47+
}
48+
}
49+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /