Skip to content

Commit 645967d

Browse files
committed
Add project files.
1 parent 9348e3d commit 645967d

File tree

114 files changed

+3930
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+3930
-0
lines changed
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{1D36206A-8C51-4D5A-A830-F6FB3A83E457}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Abstract_Factory</RootNamespace>
11+
<AssemblyName>Abstract Factory</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Program.Structural.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="App.config" />
50+
<Compile Include="Program.RealWorldCode.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<Content Include="Participants.txt" />
54+
<Content Include="UML class diagram.gif" />
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
58+
Other similar extension points exist, see Microsoft.Common.targets.
59+
<Target Name="BeforeBuild">
60+
</Target>
61+
<Target Name="AfterBuild">
62+
</Target>
63+
-->
64+
</Project>

Abstract Factory/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

Abstract Factory/Participants.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
The classes and objects participating in this pattern are:
2+
3+
AbstractFactory (ContinentFactory)
4+
declares an interface for operations that create abstract products
5+
6+
ConcreteFactory (AfricaFactory, AmericaFactory)
7+
implements the operations to create concrete product objects
8+
9+
AbstractProduct (Herbivore, Carnivore)
10+
declares an interface for a type of product object
11+
12+
Product (Wildebeest, Lion, Bison, Wolf)
13+
defines a product object to be created by the corresponding concrete factory
14+
implements the AbstractProduct interface
15+
16+
Client (AnimalWorld)
17+
uses interfaces declared by AbstractFactory and AbstractProduct classes
+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
using System;
2+
3+
/// <summary>
4+
/// Creates an instance of several families of classes.
5+
///
6+
/// Provide an interface for creating families of related or
7+
/// dependent objects without specifying their concrete classes.
8+
///
9+
/// Frequence of use: 5 high.
10+
/// </summary>
11+
namespace DoFactory.GangOfFour.Abstract.RealWorld
12+
{
13+
/// <summary>
14+
/// MainApp startup class for Real-World
15+
/// Abstract Factory Design Pattern.
16+
/// </summary>
17+
class MainApp
18+
{
19+
/// <summary>
20+
/// Entry point into console application.
21+
/// </summary>
22+
public static void Main()
23+
{
24+
// Create and run the African animal world
25+
ContinentFactory africa = new AfricaFactory();
26+
AnimalWorld world = new AnimalWorld(africa);
27+
world.RunFoodChain();
28+
29+
// Create and run the American animal world
30+
ContinentFactory america = new AmericaFactory();
31+
world = new AnimalWorld(america);
32+
world.RunFoodChain();
33+
34+
// Wait for user input
35+
Console.ReadKey();
36+
}
37+
}
38+
39+
40+
/// <summary>
41+
/// The 'AbstractFactory' abstract class
42+
/// </summary>
43+
abstract class ContinentFactory
44+
{
45+
public abstract Herbivore CreateHerbivore();
46+
public abstract Carnivore CreateCarnivore();
47+
}
48+
49+
/// <summary>
50+
/// The 'ConcreteFactory1' class
51+
/// </summary>
52+
class AfricaFactory : ContinentFactory
53+
{
54+
public override Herbivore CreateHerbivore()
55+
{
56+
return new Wildebeest();
57+
}
58+
public override Carnivore CreateCarnivore()
59+
{
60+
return new Lion();
61+
}
62+
}
63+
64+
/// <summary>
65+
/// The 'ConcreteFactory2' class
66+
/// </summary>
67+
class AmericaFactory : ContinentFactory
68+
{
69+
public override Herbivore CreateHerbivore()
70+
{
71+
return new Bison();
72+
}
73+
public override Carnivore CreateCarnivore()
74+
{
75+
return new Wolf();
76+
}
77+
}
78+
79+
/// <summary>
80+
/// The 'AbstractProductA' abstract class
81+
/// </summary>
82+
abstract class Herbivore
83+
{
84+
}
85+
86+
/// <summary>
87+
/// The 'AbstractProductB' abstract class
88+
/// </summary>
89+
abstract class Carnivore
90+
{
91+
public abstract void Eat(Herbivore h);
92+
}
93+
94+
/// <summary>
95+
/// The 'ProductA1' class
96+
/// </summary>
97+
class Wildebeest : Herbivore
98+
{
99+
}
100+
101+
/// <summary>
102+
/// The 'ProductB1' class
103+
/// </summary>
104+
class Lion : Carnivore
105+
{
106+
public override void Eat(Herbivore h)
107+
{
108+
// Eat Wildebeest
109+
Console.WriteLine(this.GetType().Name +
110+
" eats " + h.GetType().Name);
111+
}
112+
}
113+
114+
/// <summary>
115+
/// The 'ProductA2' class
116+
/// </summary>
117+
class Bison : Herbivore
118+
{
119+
}
120+
121+
/// <summary>
122+
/// The 'ProductB2' class
123+
/// </summary>
124+
class Wolf : Carnivore
125+
{
126+
public override void Eat(Herbivore h)
127+
{
128+
// Eat Bison
129+
Console.WriteLine(this.GetType().Name +
130+
" eats " + h.GetType().Name);
131+
}
132+
}
133+
134+
/// <summary>
135+
/// The 'Client' class
136+
/// </summary>
137+
class AnimalWorld
138+
{
139+
private Herbivore _herbivore;
140+
private Carnivore _carnivore;
141+
142+
// Constructor
143+
public AnimalWorld(ContinentFactory factory)
144+
{
145+
_carnivore = factory.CreateCarnivore();
146+
_herbivore = factory.CreateHerbivore();
147+
}
148+
149+
public void RunFoodChain()
150+
{
151+
_carnivore.Eat(_herbivore);
152+
}
153+
}
154+
}
155+
156+
157+
158+
// Output:
159+
//Lion eats Wildebeest
160+
//Wolf eats Bison

0 commit comments

Comments
 (0)