From 7ec5a7d404f9f40f3357668735a0e0d8fcef20ec Mon Sep 17 00:00:00 2001 From: hassa Date: Tue, 2 Apr 2024 23:43:17 +0330 Subject: [PATCH] Add Report Maker Tool Based Builder Design Pattern --- .../Contracts/IReportBuilder.cs | 12 +++++++ .../Implements/ComplexReportBuilder.cs | 30 ++++++++++++++++ .../Implements/SimpleReportBuilder.cs | 30 ++++++++++++++++ .../Model/Report.cs | 9 +++++ .../Program.cs | 36 +++++++++++++++++++ .../ReportDirector.cs | 27 ++++++++++++++ ...Pattern.Creational.Builder.Reporter.csproj | 10 ++++++ Thisisnabi.DesignPatterns.sln | 10 ++++++ 8 files changed, 164 insertions(+) create mode 100644 Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Contracts/IReportBuilder.cs create mode 100644 Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/ComplexReportBuilder.cs create mode 100644 Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/SimpleReportBuilder.cs create mode 100644 Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Model/Report.cs create mode 100644 Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Program.cs create mode 100644 Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/ReportDirector.cs create mode 100644 Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter.csproj diff --git a/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Contracts/IReportBuilder.cs b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Contracts/IReportBuilder.cs new file mode 100644 index 0000000..91e6162 --- /dev/null +++ b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Contracts/IReportBuilder.cs @@ -0,0 +1,12 @@ +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Model; + +namespace Thisisnabi.DesignPattern.Creational.Builder.Reporter.Contracts +{ + public interface IReportBuilder + { + void BuildHeader(); + void BuildBody(); + void BuildFooter(); + Report GetReport(); + } +} diff --git a/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/ComplexReportBuilder.cs b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/ComplexReportBuilder.cs new file mode 100644 index 0000000..06a9e21 --- /dev/null +++ b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/ComplexReportBuilder.cs @@ -0,0 +1,30 @@ +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Contracts; +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Model; + +namespace Thisisnabi.DesignPattern.Creational.Builder.Reporter.Implements +{ + public class ComplexReportBuilder : IReportBuilder + { + private Report report = new Report(); + + public void BuildHeader() + { + report.Header = "Complex Report Header"; + } + + public void BuildBody() + { + report.Body = "Complex Report Body"; + } + + public void BuildFooter() + { + report.Footer = "Complex Report Footer"; + } + + public Report GetReport() + { + return report; + } + } +} diff --git a/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/SimpleReportBuilder.cs b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/SimpleReportBuilder.cs new file mode 100644 index 0000000..1cfc080 --- /dev/null +++ b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Implements/SimpleReportBuilder.cs @@ -0,0 +1,30 @@ +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Contracts; +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Model; + +namespace Thisisnabi.DesignPattern.Creational.Builder.Reporter.Implements +{ + public class SimpleReportBuilder : IReportBuilder + { + private Report report = new Report(); + + public void BuildHeader() + { + report.Header = "Simple Report Header"; + } + + public void BuildBody() + { + report.Body = "Simple Report Body"; + } + + public void BuildFooter() + { + report.Footer = "Simple Report Footer"; + } + + public Report GetReport() + { + return report; + } + } +} diff --git a/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Model/Report.cs b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Model/Report.cs new file mode 100644 index 0000000..f9c7740 --- /dev/null +++ b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Model/Report.cs @@ -0,0 +1,9 @@ +namespace Thisisnabi.DesignPattern.Creational.Builder.Reporter.Model +{ + public class Report + { + public string Header { get; set; } + public string Body { get; set; } + public string Footer { get; set; } + } +} diff --git a/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Program.cs b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Program.cs new file mode 100644 index 0000000..6ba0cf3 --- /dev/null +++ b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Program.cs @@ -0,0 +1,36 @@ +using Thisisnabi.DesignPattern.Creational.Builder.Reporter; +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Implements; +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Model; + + + +ReportDirector director = new ReportDirector(); + + +SimpleReportBuilder simpleBuilder = new SimpleReportBuilder(); + +director.SetBuilder(simpleBuilder); +director.ConstructReport(); +Report simpleReport = director.GetReport(); + + +Console.WriteLine(simpleReport.Header); +Console.WriteLine(simpleReport.Body); +Console.WriteLine(simpleReport.Footer); + +Console.WriteLine("--------------------------------"); + + +ComplexReportBuilder complexBuilder = new ComplexReportBuilder(); + +director.SetBuilder(complexBuilder); +director.ConstructReport(); +Report complexReport = director.GetReport(); + + +Console.WriteLine(complexReport.Header); +Console.WriteLine(complexReport.Body); +Console.WriteLine(complexReport.Footer); + +Console.ReadKey(); + diff --git a/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/ReportDirector.cs b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/ReportDirector.cs new file mode 100644 index 0000000..6686f43 --- /dev/null +++ b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/ReportDirector.cs @@ -0,0 +1,27 @@ +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Contracts; +using Thisisnabi.DesignPattern.Creational.Builder.Reporter.Model; + +namespace Thisisnabi.DesignPattern.Creational.Builder.Reporter +{ + public class ReportDirector + { + private IReportBuilder builder; + + public void SetBuilder(IReportBuilder builder) + { + this.builder = builder; + } + + public Report GetReport() + { + return builder.GetReport(); + } + + public void ConstructReport() + { + builder.BuildHeader(); + builder.BuildBody(); + builder.BuildFooter(); + } + } +} diff --git a/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter.csproj b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/Creational/Builder/Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter/Thisisnabi.DesignPattern.Creational.Builder.Reporter.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Thisisnabi.DesignPatterns.sln b/Thisisnabi.DesignPatterns.sln index 5a2f814..0d3d7cf 100644 --- a/Thisisnabi.DesignPatterns.sln +++ b/Thisisnabi.DesignPatterns.sln @@ -35,6 +35,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Thisisnabi.DesignPattern.Cr EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebFramework", "WebFramework", "{6CEB7E03-A7EA-4661-9788-A40D0573AE48}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Reporter", "Reporter", "{88F4F441-3244-403E-83C8-E9F3E1EEAEE8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thisisnabi.DesignPattern.Creational.Builder.Reporter", "Creational\Builder\Reporter\Thisisnabi.DesignPattern.Creational.Builder.Reporter\Thisisnabi.DesignPattern.Creational.Builder.Reporter.csproj", "{5F867A95-C0B3-4EDF-8F01-D28A6E55CF65}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +65,10 @@ Global {75DF1A45-0F4C-4877-B7AC-82E305D18F46}.Debug|Any CPU.Build.0 = Debug|Any CPU {75DF1A45-0F4C-4877-B7AC-82E305D18F46}.Release|Any CPU.ActiveCfg = Release|Any CPU {75DF1A45-0F4C-4877-B7AC-82E305D18F46}.Release|Any CPU.Build.0 = Release|Any CPU + {5F867A95-C0B3-4EDF-8F01-D28A6E55CF65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F867A95-C0B3-4EDF-8F01-D28A6E55CF65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F867A95-C0B3-4EDF-8F01-D28A6E55CF65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F867A95-C0B3-4EDF-8F01-D28A6E55CF65}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -79,6 +87,8 @@ Global {DF25837E-E5FD-4CD0-8E56-301FC6FBF7EE} = {23E0BB9D-76A0-4477-9148-CBBACB473367} {75DF1A45-0F4C-4877-B7AC-82E305D18F46} = {6CEB7E03-A7EA-4661-9788-A40D0573AE48} {6CEB7E03-A7EA-4661-9788-A40D0573AE48} = {4D3C53A2-569A-4412-AA26-FB317A8FFEA1} + {88F4F441-3244-403E-83C8-E9F3E1EEAEE8} = {4D3C53A2-569A-4412-AA26-FB317A8FFEA1} + {5F867A95-C0B3-4EDF-8F01-D28A6E55CF65} = {88F4F441-3244-403E-83C8-E9F3E1EEAEE8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {98ABEC4C-900E-4FA2-B829-BEA7839B73F3}