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

Appearance settings

Commit fd2e12f

Browse filesBrowse files
committed
Abstract Factory
1 parent 56ebfc4 commit fd2e12f
Copy full SHA for fd2e12f

File tree

Expand file treeCollapse file tree

10 files changed

+122
-2
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+122
-2
lines changed
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace AbstractFactory.Chair
2+
{
3+
public interface IChair
4+
{
5+
string Print();
6+
7+
}
8+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace AbstractFactory.Chair
2+
{
3+
class ModernChair : IChair
4+
{
5+
public string Print()
6+
{
7+
return "The result of the Modern Chair.";
8+
}
9+
10+
}
11+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace AbstractFactory.Chair
2+
{
3+
class VictorianChair : IChair
4+
{
5+
public string Print()
6+
{
7+
return "The result of the Victorian Chair.";
8+
}
9+
10+
}
11+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using AbstractFactory.Chair;
2+
using AbstractFactory.Sofa;
3+
4+
namespace AbstractFactory.Factory
5+
{
6+
public interface IFurnitureFactory
7+
{
8+
ISofa CreateSofa();
9+
10+
IChair CreateModern();
11+
}
12+
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using AbstractFactory.Chair;
2+
using AbstractFactory.Sofa;
3+
4+
namespace AbstractFactory.Factory
5+
{
6+
class ModernFurnitureFactory : IFurnitureFactory
7+
{
8+
public ISofa CreateSofa()
9+
{
10+
return new ModernSofa();
11+
}
12+
13+
public IChair CreateModern()
14+
{
15+
return new ModernChair();
16+
}
17+
}
18+
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using AbstractFactory.Chair;
2+
using AbstractFactory.Sofa;
3+
4+
namespace AbstractFactory.Factory
5+
{
6+
class VictorianFurnitureFactory : IFurnitureFactory
7+
{
8+
public ISofa CreateSofa()
9+
{
10+
return new VictorianSofa();
11+
}
12+
13+
public IChair CreateModern()
14+
{
15+
return new VictorianChair();
16+
}
17+
}
18+
}
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
using System;
1+
using AbstractFactory.Factory;
2+
using System;
23

34
namespace AbstractFactory
45
{
56
class Program
67
{
78
static void Main(string[] args)
89
{
9-
Console.WriteLine("Hello World!");
10+
Console.WriteLine("Client: Testing client code with the first factory type modern furniture");
11+
ClientMethod(new ModernFurnitureFactory());
12+
Console.WriteLine();
13+
14+
Console.WriteLine("Client: Testing the same client code with the second factory type victorian furniture");
15+
ClientMethod(new VictorianFurnitureFactory());
16+
}
17+
18+
public static void ClientMethod(IFurnitureFactory factory)
19+
{
20+
var sofa = factory.CreateSofa();
21+
var modern = factory.CreateModern();
22+
23+
Console.WriteLine(sofa.Print());
24+
Console.WriteLine(modern.Print());
1025
}
1126
}
1227
}
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AbstractFactory.Sofa
2+
{
3+
public interface ISofa
4+
{
5+
string Print();
6+
}
7+
}
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace AbstractFactory.Sofa
2+
{
3+
class ModernSofa : ISofa
4+
{
5+
public string Print()
6+
{
7+
return "The result of the Modern Sofa.";
8+
}
9+
}
10+
}
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace AbstractFactory.Sofa
2+
{
3+
class VictorianSofa : ISofa
4+
{
5+
public string Print()
6+
{
7+
return "The result of the Victorian Sofa.";
8+
}
9+
}
10+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.