diff --git a/06 - Template Method/.gitignore b/06 - Template Method/.gitignore new file mode 100644 index 0000000..112d089 --- /dev/null +++ b/06 - Template Method/.gitignore @@ -0,0 +1,598 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +################### +# compiled source # +################### +*.com +*.class +*.dll +*.exe +*.pdb +*.dll.config +*.cache +*.suo +# Include dlls if they’re in the NuGet packages directory +!/packages/*/lib/*.dll +# Include dlls if they're in the CommonReferences directory +!*CommonReferences/*.dll +#################### +# VS Upgrade stuff # +#################### +_UpgradeReport_Files/ +############### +# Directories # +############### +bin/ +obj/ +TestResults/ +################### +# Web publish log # +################### +*.Publish.xml +############# +# Resharper # +############# +/_ReSharper.* +*.ReSharper.* +############ +# Packages # +############ +# it’s better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip +###################### +# Logs and databases # +###################### +*.log +*.sqlite +# OS generated files # +###################### +.DS_Store? +ehthumbs.db +Icon? +Thumbs.db + + +# User-specific files +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studo 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt \ No newline at end of file diff --git a/06 - Template Method/NoPatterns/NoPatterns.csproj b/06 - Template Method/NoPatterns/NoPatterns.csproj new file mode 100644 index 0000000..23df604 --- /dev/null +++ b/06 - Template Method/NoPatterns/NoPatterns.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/06 - Template Method/NoPatterns/PizzaCalabresa.cs b/06 - Template Method/NoPatterns/PizzaCalabresa.cs new file mode 100644 index 0000000..8205738 --- /dev/null +++ b/06 - Template Method/NoPatterns/PizzaCalabresa.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NoPatterns +{ + public class PizzaCalabresa + { + public string Ingredientes { get; set; } + public string PizzaSelected { get; set; } + + public PizzaCalabresa() + { + Ingredientes = "Ingredientes: 300g de calabresa fatiada, 50g de cebola em rodelas, azeitonas"; + PizzaSelected = "Calabresa"; + } + + public void Init() + { + Console.WriteLine($"Pizza de {PizzaSelected}:"); + } + + public void SelectIngredients() + { + Console.WriteLine($"{Ingredientes}"); + } + + public void Duration() + { + Console.WriteLine("Tempo de duração: 20min."); + } + + public void Bake() + { + Console.WriteLine($"Assando a pizza {PizzaSelected} em forno baixo."); + } + + public void Make() + { + Init(); + SelectIngredients(); + Duration(); + Bake(); + Console.WriteLine($"A Pizza de {PizzaSelected} esta pronta."); + } + } +} diff --git a/06 - Template Method/NoPatterns/PizzaFrango.cs b/06 - Template Method/NoPatterns/PizzaFrango.cs new file mode 100644 index 0000000..27c1bfc --- /dev/null +++ b/06 - Template Method/NoPatterns/PizzaFrango.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NoPatterns +{ + public class PizzaFrango + { + public string Ingredients { get; set; } + public string PizzaSelected { get; set; } + + public PizzaFrango() + { + Ingredients = "300g de frango desfiado, e algumas azeitonas"; + PizzaSelected = "Frango"; + } + + public void Init() + { + Console.WriteLine($"Fazendo Pizza de {PizzaSelected}:"); + } + + public void SelectIngredients() + { + Console.WriteLine($"{Ingredients}"); + } + + public void Duration() + { + Console.WriteLine("Tempo de duração: 20min."); + } + + public void Bake() + { + Console.WriteLine($"Assando a pizza {PizzaSelected} em forno baixo."); + } + + public void Make() + { + Init(); + SelectIngredients(); + Duration(); + Bake(); + Console.WriteLine($"A Pizza de {PizzaSelected} esta pronta."); + } + } +} diff --git a/06 - Template Method/NoPatterns/PizzaMussarela.cs b/06 - Template Method/NoPatterns/PizzaMussarela.cs new file mode 100644 index 0000000..79ab316 --- /dev/null +++ b/06 - Template Method/NoPatterns/PizzaMussarela.cs @@ -0,0 +1,45 @@ +using System; + +namespace NoPatterns +{ + public class PizzaMussarela + { + public string itensDaPizza { get; set; } + public string pizzaSelecionada { get; set; } + + public PizzaMussarela() + { + itensDaPizza = $"300g de mussarela, 8 fatias de tomate, oregano, e azeitonas."; + pizzaSelecionada = "Pizza de mussarela"; + } + + public void Init() + { + Console.WriteLine($"Vamos fazer pizza de {pizzaSelecionada}:"); + } + + public void SelectIngredients() + { + Console.WriteLine($"{itensDaPizza}"); + } + + public void Duration() + { + Console.WriteLine("duração: 20min."); + } + + public void Bake() + { + Console.WriteLine($"Assando a pizza {pizzaSelecionada} em forno baixo."); + } + + public void Make() + { + Init(); + SelectIngredients(); + Duration(); + Bake(); + Console.WriteLine($"A Pizza de {pizzaSelecionada} esta pronta."); + } + } +} \ No newline at end of file diff --git a/06 - Template Method/NoPatterns/Program.cs b/06 - Template Method/NoPatterns/Program.cs new file mode 100644 index 0000000..e475c6d --- /dev/null +++ b/06 - Template Method/NoPatterns/Program.cs @@ -0,0 +1,24 @@ +using System; + +namespace NoPatterns +{ + class Program + { + static void Main(string[] args) + { + PizzaMussarela pizzaMussarela = new PizzaMussarela(); + pizzaMussarela.Make(); + Console.WriteLine(); + + PizzaCalabresa pizzaCalabresa = new PizzaCalabresa(); + pizzaCalabresa.Make(); + Console.WriteLine(); + + PizzaFrango pizzaFrango = new PizzaFrango(); + pizzaFrango.Make(); + Console.WriteLine(); + + Console.ReadKey(); + } + } +} diff --git a/06 - Template Method/TemplateMethodPattern.sln b/06 - Template Method/TemplateMethodPattern.sln new file mode 100644 index 0000000..2fc66e9 --- /dev/null +++ b/06 - Template Method/TemplateMethodPattern.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2026 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Problem", "Problem", "{31B180B6-80BE-4AB7-A920-7E2EC20C5344}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pattern", "Pattern", "{FC96348F-3A7A-4DB9-8C9E-84883C9BAC77}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NoPatterns", "NoPatterns\NoPatterns.csproj", "{94A88632-3024-4839-9C1F-281A841BF53D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UsingPattern", "UsingPattern\UsingPattern.csproj", "{DF6422BE-B0A6-4F61-A152-9CB4B86B64B7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {94A88632-3024-4839-9C1F-281A841BF53D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94A88632-3024-4839-9C1F-281A841BF53D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94A88632-3024-4839-9C1F-281A841BF53D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94A88632-3024-4839-9C1F-281A841BF53D}.Release|Any CPU.Build.0 = Release|Any CPU + {DF6422BE-B0A6-4F61-A152-9CB4B86B64B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF6422BE-B0A6-4F61-A152-9CB4B86B64B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF6422BE-B0A6-4F61-A152-9CB4B86B64B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF6422BE-B0A6-4F61-A152-9CB4B86B64B7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {94A88632-3024-4839-9C1F-281A841BF53D} = {31B180B6-80BE-4AB7-A920-7E2EC20C5344} + {DF6422BE-B0A6-4F61-A152-9CB4B86B64B7} = {FC96348F-3A7A-4DB9-8C9E-84883C9BAC77} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0F0D8DB7-94AF-4618-8F3D-C9FC4212B010} + EndGlobalSection +EndGlobal diff --git a/06 - Template Method/UsingPattern/Pizza.cs b/06 - Template Method/UsingPattern/Pizza.cs new file mode 100644 index 0000000..cbd0043 --- /dev/null +++ b/06 - Template Method/UsingPattern/Pizza.cs @@ -0,0 +1,44 @@ +using System; + +namespace UsingPattern +{ + /// + /// Representação de Abstract class no diagrama + /// + public abstract class Pizza + { + #region Primitive + public abstract string PizzaSelected { get; set; } + public abstract string Ingredients { get; set; } + public abstract void SelectIngredients(); + public abstract void Bake(); + + public virtual void Init() + { + Console.WriteLine($"Pizza de {PizzaSelected}:"); + } + public virtual void Slice() + { + Console.WriteLine($"Fatiando a pizza de { PizzaSelected } em 8 partes."); + } + public virtual void Duration() + { + Console.WriteLine("Tempo de preparo: 20min"); + } + #endregion + + #region template + public void Make() + { + Init(); + SelectIngredients(); + Bake(); + Duration(); + Slice(); + Console.WriteLine($"A Pizza de {PizzaSelected} esta pronta."); + Console.WriteLine(); + Console.WriteLine(); + } + #endregion + } +} \ No newline at end of file diff --git a/06 - Template Method/UsingPattern/PizzaCalabresa.cs b/06 - Template Method/UsingPattern/PizzaCalabresa.cs new file mode 100644 index 0000000..58e77af --- /dev/null +++ b/06 - Template Method/UsingPattern/PizzaCalabresa.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace UsingPattern +{ + public class PizzaCalabresa : Pizza + { + public override string PizzaSelected { get; set; } + public override string Ingredients { get; set; } + + public PizzaCalabresa() + { + Ingredients = "Ingredientes: 300g de calabresa fatiada, 50g de cebola em rodelas, azeitonas"; + PizzaSelected = "Calabresa"; + } + + public override void Bake() + { + Console.WriteLine($"Assando a pizza {PizzaSelected} em forno médio."); + } + + public override void SelectIngredients() + { + Console.WriteLine($"{Ingredients}"); + } + } +} \ No newline at end of file diff --git a/06 - Template Method/UsingPattern/PizzaFrango.cs b/06 - Template Method/UsingPattern/PizzaFrango.cs new file mode 100644 index 0000000..bbf60cb --- /dev/null +++ b/06 - Template Method/UsingPattern/PizzaFrango.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace UsingPattern +{ + public class PizzaFrango : Pizza + { + public override string PizzaSelected { get; set; } + public override string Ingredients { get; set; } + + public PizzaFrango() + { + Ingredients = "Ingredientes: 300g de frango desfiado, e algumas azeitonas"; + PizzaSelected = "Frango"; + } + + public override void Bake() + { + Console.WriteLine($"Assando a pizza {PizzaSelected} em forno alto."); + } + + public override void SelectIngredients() + { + Console.WriteLine($"{Ingredients}"); + } + } +} diff --git a/06 - Template Method/UsingPattern/PizzaMussarela.cs b/06 - Template Method/UsingPattern/PizzaMussarela.cs new file mode 100644 index 0000000..82b7243 --- /dev/null +++ b/06 - Template Method/UsingPattern/PizzaMussarela.cs @@ -0,0 +1,35 @@ +using System; + +namespace UsingPattern +{ + /// + /// Representação da classe Concret no diagrama + /// + public class PizzaMussarela : Pizza + { + public override string Ingredients { get; set; } + public override string PizzaSelected { get; set; } + + public PizzaMussarela() + { + Ingredients = $"Ingredientes: 300g de mussarela, 8 fatias de tomate, oregano, e azeitonas."; + PizzaSelected = "Mussarela"; + } + + public override void SelectIngredients() + { + Console.WriteLine($"{Ingredients}"); + } + + //public override void Slice() + //{ + // base.Slice(); + // Console.WriteLine("Embalar a pizza depois de fatiar."); + //} + + public override void Bake() + { + Console.WriteLine($"Assando a pizza {PizzaSelected} em forno baixo."); + } + } +} \ No newline at end of file diff --git a/06 - Template Method/UsingPattern/Program.cs b/06 - Template Method/UsingPattern/Program.cs new file mode 100644 index 0000000..01f023d --- /dev/null +++ b/06 - Template Method/UsingPattern/Program.cs @@ -0,0 +1,22 @@ +using System; + +namespace UsingPattern +{ + class Program + { + static void Main(string[] args) + { + PizzaMussarela pizzaDeMussarela = new PizzaMussarela(); + pizzaDeMussarela.Make(); + + PizzaCalabresa pizzaCalabresa = new PizzaCalabresa(); + pizzaCalabresa.Make(); + + PizzaFrango pizzaFrango = new PizzaFrango(); + pizzaFrango.Make(); + + + Console.ReadKey(); + } + } +} diff --git a/06 - Template Method/UsingPattern/UsingPattern.csproj b/06 - Template Method/UsingPattern/UsingPattern.csproj new file mode 100644 index 0000000..23df604 --- /dev/null +++ b/06 - Template Method/UsingPattern/UsingPattern.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/06 - Template Method/readme.md b/06 - Template Method/readme.md index dc968ff..7a74c3a 100644 --- a/06 - Template Method/readme.md +++ b/06 - Template Method/readme.md @@ -1 +1,23 @@ -The author's footnote to Iterator explains that a method called "Traverse" in the Iterator example code is an example of a Template Method. This pattern also reenforces Strategy and Factory Method. \ No newline at end of file +# Template method +#### behavioral +O objetivo deste padrão é definir o esqueleto de um algoritmo dentro de um método, +tranferindo alguns de seus passos para as subclasses, permitindo assim que subclasses redefinam certos passos de um algoritmo sem alterar a estrutura do mesmo. + +### Diagrama de classe UML : +![alt text](https://www.thiengo.com.br/img/post/normal/2mukgjhalorsrofoqh4tsmkoo7d6109366674f9e6415c8aac1e22b99ea.jpg) + +### Os participantes : +- A ClasseTemplateAbstract define um conjunto de operações abstratas que podem (opcionalmente) ser implementadas pelos objetos da ClasseConcreta. Também implementa um método de modelo que controla a ordem em que essas operações abstratas ocorrem. +- Os objetos ClasseConcreta implementam as operações definidas pela ClasseTempateAbstract. + +### Quando usar : +- É necessário implementar as partes invariantes de um algoritimo uma única vez e deixar para subclasses a implentação da parte variante. +- Há comportamento semelhante entre subclasses. +- É necessário controlar extensões de classes com métodos. + + +### Vantagens: +- A principal vantagem do padrão Template Method é a facilidade de alteração do algoritmo principal. + +### Desvantagens +- após instanciar um algoritmo, não será possível alterar o passo da execução; diff --git a/06 - Template Method/template.png b/06 - Template Method/template.png new file mode 100644 index 0000000..b4b512c Binary files /dev/null and b/06 - Template Method/template.png differ