Skip to content

Commit db22371

Browse files
committed
Restructure the project
1 parent 699d6dc commit db22371

23 files changed

+122
-178
lines changed

src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Factories/Common/IRestaurantFactory.cs renamed to src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Common/Factories/IRestaurantFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using RestaurantAbstractFactory.Meals.Common;
1+
using RestaurantAbstractFactory.Common.Products;
22

3-
namespace RestaurantAbstractFactory.Factories.Common;
3+
namespace RestaurantAbstractFactory.Common.Factories;
44

55
/// <summary>
66
/// The Abstract Factory interface declares a set of methods for creating each of the abstract products.

src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Meals/Common/IAppetizer.cs renamed to src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Common/Products/IAppetizer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
namespace RestaurantAbstractFactory.Meals.Common;
1+
namespace RestaurantAbstractFactory.Common.Products;
22

33
/// <summary>
44
/// Abstract Products declare interfaces for a set of distinct
55
/// but related products which make up a product family.
66
/// Each abstract product must be implemented in all given variants, which for this project are
7-
/// <see cref="FastFood.FastFoodAppetizer"/> and <seealso cref="Vegetarian.VegetarianAppetizer"/>
7+
/// <see cref="FastFood.Products.FastFoodAppetizer"/> and <seealso cref="Vegetarian.Products.VegetarianAppetizer"/>
88
/// </summary>
99
public interface IAppetizer : IMeal
1010
{
1111
bool IsBroth();
12-
}
12+
}

src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Meals/Common/IDessert.cs renamed to src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Common/Products/IDessert.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RestaurantAbstractFactory.Meals.Common;
1+
namespace RestaurantAbstractFactory.Common.Products;
22

33
public interface IDessert : IMeal
44
{

src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Meals/Common/IMainCourse.cs renamed to src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Common/Products/IMainCourse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RestaurantAbstractFactory.Meals.Common;
1+
namespace RestaurantAbstractFactory.Common.Products;
22

33
public interface IMainCourse : IMeal
44
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace RestaurantAbstractFactory.Common.Products;
2+
3+
public interface IMeal
4+
{
5+
void ShowDescription();
6+
}

src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Executor.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using DesignPatternsLibrary.PatternExecutors;
2-
using RestaurantAbstractFactory.Factories;
3-
using RestaurantAbstractFactory.Factories.Common;
4-
using RestaurantAbstractFactory.Meals.Common;
2+
using RestaurantAbstractFactory.Common.Factories;
3+
using RestaurantAbstractFactory.Common.Products;
4+
using RestaurantAbstractFactory.Vegetarian;
55

66
namespace RestaurantAbstractFactory;
77

@@ -24,9 +24,7 @@ public override void Execute()
2424
dessert.ShowSugarAmount();
2525
}
2626

27-
private IRestaurantFactory LoadFactory()
28-
{
29-
// The factory is usually chosen based on some value from the configuration
30-
return new VegetarianRestaurantFactory();
31-
}
32-
}
27+
// The factory is hardcoded in this example, but it's usually resolved from a configuration.
28+
private static IRestaurantFactory LoadFactory() =>
29+
new VegetarianRestaurantFactory();
30+
}

src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Factories/FastFoodRestaurantFactory.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/CreationalPatterns/AbstractFactory/RestaurantAbstractFactory/Factories/VegetarianRestaurantFactory.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using RestaurantAbstractFactory.Common.Factories;
2+
using RestaurantAbstractFactory.Common.Products;
3+
using RestaurantAbstractFactory.FastFood.Products;
4+
5+
namespace RestaurantAbstractFactory.FastFood;
6+
7+
/// <summary>
8+
/// Concrete Factories implement creation methods of the abstract factory.
9+
/// Each concrete factory corresponds to a specific variant of products and creates only those product variants.
10+
/// </summary>
11+
public class FastFoodRestaurantFactory : IRestaurantFactory
12+
{
13+
public IAppetizer PrepareAppetizer() => new FastFoodAppetizer();
14+
15+
public IMainCourse PrepareMainCourse() => new FastFoodMainCourse();
16+
17+
public IDessert PrepareDessert() => new FastFoodDessert();
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using RestaurantAbstractFactory.Common.Products;
2+
3+
namespace RestaurantAbstractFactory.FastFood.Products;
4+
5+
/// <summary>
6+
/// Concrete Products are various implementations of abstract products, grouped by variants.
7+
/// </summary>
8+
public class FastFoodAppetizer : IAppetizer
9+
{
10+
public void ShowDescription() => Console.WriteLine("Bread bites - with garlic and marinara sauce.");
11+
12+
public bool IsBroth() => false;
13+
}

0 commit comments

Comments
 (0)