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 4e8594e

Browse files
author
anupavanm
committed
Factory method pattern
1 parent e5e140a commit 4e8594e

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

‎DesignPatterns.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27004.2009
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern", "FactoryPattern\FactoryPattern.csproj", "{EC684E1B-EA3F-47FD-8F45-175C56667F13}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryMethodPattern", "FactoryMethodPattern\FactoryMethodPattern.csproj", "{493DBC90-47D2-49F5-906D-14F3AFDDF9F8}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{EC684E1B-EA3F-47FD-8F45-175C56667F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{EC684E1B-EA3F-47FD-8F45-175C56667F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{EC684E1B-EA3F-47FD-8F45-175C56667F13}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{493DBC90-47D2-49F5-906D-14F3AFDDF9F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{493DBC90-47D2-49F5-906D-14F3AFDDF9F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{493DBC90-47D2-49F5-906D-14F3AFDDF9F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{493DBC90-47D2-49F5-906D-14F3AFDDF9F8}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
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>

‎FactoryMethodPattern/Program.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
3+
namespace FactoryMethodPattern
4+
{
5+
interface IInterviewer
6+
{
7+
void AskQuestions();
8+
}
9+
10+
class Developer : IInterviewer
11+
{
12+
public void AskQuestions()
13+
{
14+
Console.WriteLine("Asking about design patterns!");
15+
}
16+
}
17+
18+
class CommunityExecutive : IInterviewer
19+
{
20+
public void AskQuestions()
21+
{
22+
Console.WriteLine("Asking about community building!");
23+
}
24+
}
25+
26+
abstract class HiringManager
27+
{
28+
// Factory method
29+
abstract protected IInterviewer MakeInterviewer();
30+
public void TakeInterview()
31+
{
32+
var interviewer = this.MakeInterviewer();
33+
interviewer.AskQuestions();
34+
}
35+
}
36+
37+
class DevelopmentManager : HiringManager
38+
{
39+
protected override IInterviewer MakeInterviewer()
40+
{
41+
return new Developer();
42+
}
43+
}
44+
45+
class MarketingManager : HiringManager
46+
{
47+
protected override IInterviewer MakeInterviewer()
48+
{
49+
return new CommunityExecutive();
50+
}
51+
}
52+
53+
class Program
54+
{
55+
static void Main(string[] args)
56+
{
57+
var devManager = new DevelopmentManager();
58+
devManager.TakeInterview(); //Output : Asking about design patterns!
59+
60+
var marketingManager = new MarketingManager();
61+
marketingManager.TakeInterview();//Output : Asking about community building!
62+
63+
Console.ReadLine();
64+
}
65+
}
66+
}

0 commit comments

Comments
(0)

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