Click here to Skip to main content
15,881,173 members
Articles / Programming Languages / C#

Illustrating Factory pattern with a very basic example

Rate me:
Please Sign up or sign in to vote.
4.80/5 (33 votes)
2 Oct 2012CPOL2 min read 131.4K   2.5K   28  
A simplified explanation of Factory pattern with sample C# .NET code.

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "DesignPatterns\Client.csproj", "{65377370-2C67-4989-9133-F27328213FDD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Choice", "Choice\Choice.csproj", "{08FAFAF9-68D3-4D32-9473-94A651D8398B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChoiceInterface", "ChoiceInterface\ChoiceInterface.csproj", "{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryClass", "FactoryClass\FactoryClass.csproj", "{03DE6D2A-8433-48D6-878D-59039C34F589}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Debug|Mixed Platforms = Debug|Mixed Platforms
		Debug|x86 = Debug|x86
		Release|Any CPU = Release|Any CPU
		Release|Mixed Platforms = Release|Mixed Platforms
		Release|x86 = Release|x86
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{65377370-2C67-4989-9133-F27328213FDD}.Debug|Any CPU.ActiveCfg = Debug|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Debug|Mixed Platforms.Build.0 = Debug|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Debug|x86.ActiveCfg = Debug|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Debug|x86.Build.0 = Debug|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Release|Any CPU.ActiveCfg = Release|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Release|Mixed Platforms.ActiveCfg = Release|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Release|Mixed Platforms.Build.0 = Release|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Release|x86.ActiveCfg = Release|x86
		{65377370-2C67-4989-9133-F27328213FDD}.Release|x86.Build.0 = Release|x86
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Debug|x86.ActiveCfg = Debug|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Release|Any CPU.Build.0 = Release|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{08FAFAF9-68D3-4D32-9473-94A651D8398B}.Release|x86.ActiveCfg = Release|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Debug|x86.ActiveCfg = Debug|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Release|Any CPU.Build.0 = Release|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{F88D52F9-2E54-4DA5-8333-D83406A8A4EC}.Release|x86.ActiveCfg = Release|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Debug|x86.ActiveCfg = Debug|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Release|Any CPU.Build.0 = Release|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Release|Mixed Platforms.Build.0 = Release|Any CPU
		{03DE6D2A-8433-48D6-878D-59039C34F589}.Release|x86.ActiveCfg = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
United States United States
Experienced Lead developer having 17+ years with a passion for developing innovative programs that expedite the efficiency and effectiveness of organizational success. Well-versed in technology and writing code to create systems that are reliable and user-friendly. A skilled leader who has the proven ability to motivate, educate, and manage a team of professionals to build software programs and effectively track changes. Confident communicator, strategic thinker, and innovative creator to develop software that is customized to meet a company’s organizational needs and further its success.

Comments and Discussions