From 33c60b98d35031a8b846b13f6c3fb0155729fa67 Mon Sep 17 00:00:00 2001 From: "Bruno B. Melo" Date: Sun, 25 Nov 2018 18:18:11 -0200 Subject: [PATCH 1/4] Firts commit --- 06 - Template Method/.gitignore | 598 ++++++++++++++++++++++++++++++ 06 - Template Method/template.png | Bin 0 -> 5629 bytes 2 files changed, 598 insertions(+) create mode 100644 06 - Template Method/.gitignore create mode 100644 06 - Template Method/template.png 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/template.png b/06 - Template Method/template.png new file mode 100644 index 0000000000000000000000000000000000000000..b4b512c8af002c9ba2ba1de232043382e25b65bc GIT binary patch literal 5629 zcmW+#2UrtZ6I~P)Q6B`55?UY>k)m`(z@_?5B?6&I5fD%plwPEXGPl5EwyV6oDBC z%(MrG!c3A7vkrw36h={)fx=ABa15Bq9AY*zV1xmq44A=y0oJ`>(qp>KEMj`dw2SEs z%S9ZHr3HjzO+;`gibEMVra4R>SOP&H3kG4y!&HLhHx6Q{20<)r1VT{=Wk5_Zn7o-3 znQT}KAux)6NfpH+086u=Fq+0KMUI@AnUwA+_I3x>oZh zBWAzRsy{)c`Nr@_ikY}>MwhZ2aDCNGNWlpgyFd5N!#^gGO@;&3W~*1;wl%LW50#of zv3lOJ`E?-8eBs;m{@f_!0AbHeMU1YqHqSLLfy z8!INxH~AzE9S6wL6h`b(jn9m`+{Pz9-s5w~WB5<&b%`1eiu3;ydL zWw=T7M-`HCg#(AM`?iGcee#i=BMbWMRc+bD|0UEj8efnfIv9{*WLT!(I`x3v1)sd* zc1zRhY+mA`(73Q(tJ%tA^4<`~41Xq-LoDio#KmkrP(y0L#+?7`JDoxioKY6ntD8gq z{l%9A;ZnGPh+2dDkRJ}ynkl)O4KTxb^4 zmql5>MJ+b`f*BPglKmwsot_c`lCN!-KnDE_tTKaBgso2 z8<@)7tsJMYW*~ZBYrIz|^JsRjLI}lAFHD_1WI#5oMd+<~xdQj|BgdpSh71M#=@-Ps zd+JSed0$@}G7q7Ry|ES;-RLsoGF0zZdfDah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_6<(7N*XL{Q{P#`zp~$K{ z-`<%AN1D#|-IAo(Vuw;~*>6eXS1$iZ9Wr?2r)zgtIAYMTH)KWdvW|#Q>IC1!X3(PO zvtqVqF}-t_9fxkEwv%bh%y%Z~0KCU;%t`%{)#tsKAhs=|1qEdYJgaTZWrS6fwBKe@s5@!ee&a z@U`0(hfdKZyNCC+?VpSfpYkcob2C2^=q?gKl{nR{GvYei93cPrHP)zH+PbhfXXxP< xO5k&zDc*(1)t7d+(iHx5v?!Eb`LhV6^Ui(g^1QNi?e>!Q<0aA@fsG9~_djVjX=4BY literal 0 HcmV?d00001 From e4aa7d3d548e5a1624b10dcb33a647ad722d267b Mon Sep 17 00:00:00 2001 From: "Bruno B. Melo" Date: Sun, 25 Nov 2018 18:48:24 -0200 Subject: [PATCH 2/4] Update readme --- 06 - Template Method/readme.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/06 - Template Method/readme.md b/06 - Template Method/readme.md index dc968ff..fa13e0b 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; From 44d51f6ba090c4c08a5f74ea4c1587e9baa36160 Mon Sep 17 00:00:00 2001 From: "Bruno B. Melo" Date: Sun, 25 Nov 2018 18:49:16 -0200 Subject: [PATCH 3/4] Update readme --- 06 - Template Method/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/06 - Template Method/readme.md b/06 - Template Method/readme.md index fa13e0b..7a74c3a 100644 --- a/06 - Template Method/readme.md +++ b/06 - Template Method/readme.md @@ -3,10 +3,10 @@ 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 : +### Diagrama de classe UML : ![alt text](https://www.thiengo.com.br/img/post/normal/2mukgjhalorsrofoqh4tsmkoo7d6109366674f9e6415c8aac1e22b99ea.jpg) -#### Os participantes : +### 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. From 9ef466e7fc0e23ab9dca21a863cd307294f349db Mon Sep 17 00:00:00 2001 From: "Bruno B. Melo" Date: Sun, 25 Nov 2018 19:17:38 -0200 Subject: [PATCH 4/4] Template method --- .../NoPatterns/NoPatterns.csproj | 8 ++++ .../NoPatterns/PizzaCalabresa.cs | 47 +++++++++++++++++++ .../NoPatterns/PizzaFrango.cs | 47 +++++++++++++++++++ .../NoPatterns/PizzaMussarela.cs | 45 ++++++++++++++++++ 06 - Template Method/NoPatterns/Program.cs | 24 ++++++++++ .../TemplateMethodPattern.sln | 39 +++++++++++++++ 06 - Template Method/UsingPattern/Pizza.cs | 44 +++++++++++++++++ .../UsingPattern/PizzaCalabresa.cs | 28 +++++++++++ .../UsingPattern/PizzaFrango.cs | 28 +++++++++++ .../UsingPattern/PizzaMussarela.cs | 35 ++++++++++++++ 06 - Template Method/UsingPattern/Program.cs | 22 +++++++++ .../UsingPattern/UsingPattern.csproj | 8 ++++ 12 files changed, 375 insertions(+) create mode 100644 06 - Template Method/NoPatterns/NoPatterns.csproj create mode 100644 06 - Template Method/NoPatterns/PizzaCalabresa.cs create mode 100644 06 - Template Method/NoPatterns/PizzaFrango.cs create mode 100644 06 - Template Method/NoPatterns/PizzaMussarela.cs create mode 100644 06 - Template Method/NoPatterns/Program.cs create mode 100644 06 - Template Method/TemplateMethodPattern.sln create mode 100644 06 - Template Method/UsingPattern/Pizza.cs create mode 100644 06 - Template Method/UsingPattern/PizzaCalabresa.cs create mode 100644 06 - Template Method/UsingPattern/PizzaFrango.cs create mode 100644 06 - Template Method/UsingPattern/PizzaMussarela.cs create mode 100644 06 - Template Method/UsingPattern/Program.cs create mode 100644 06 - Template Method/UsingPattern/UsingPattern.csproj 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 + + +