Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template method #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Template method
  • Loading branch information
brbarmex committed Nov 25, 2018
commit 9ef466e7fc0e23ab9dca21a863cd307294f349db
8 changes: 8 additions & 0 deletions 06 - Template Method/NoPatterns/NoPatterns.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>
47 changes: 47 additions & 0 deletions 06 - Template Method/NoPatterns/PizzaCalabresa.cs
Original file line number Diff line number Diff line change
@@ -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.");
}
}
}
47 changes: 47 additions & 0 deletions 06 - Template Method/NoPatterns/PizzaFrango.cs
Original file line number Diff line number Diff line change
@@ -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.");
}
}
}
45 changes: 45 additions & 0 deletions 06 - Template Method/NoPatterns/PizzaMussarela.cs
Original file line number Diff line number Diff line change
@@ -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.");
}
}
}
24 changes: 24 additions & 0 deletions 06 - Template Method/NoPatterns/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
39 changes: 39 additions & 0 deletions 06 - Template Method/TemplateMethodPattern.sln
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions 06 - Template Method/UsingPattern/Pizza.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;

namespace UsingPattern
{
/// <summary>
/// Representação de Abstract class no diagrama
/// </summary>
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
}
}
28 changes: 28 additions & 0 deletions 06 - Template Method/UsingPattern/PizzaCalabresa.cs
Original file line number Diff line number Diff line change
@@ -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}");
}
}
}
28 changes: 28 additions & 0 deletions 06 - Template Method/UsingPattern/PizzaFrango.cs
Original file line number Diff line number Diff line change
@@ -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}");
}
}
}
35 changes: 35 additions & 0 deletions 06 - Template Method/UsingPattern/PizzaMussarela.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace UsingPattern
{
/// <summary>
/// Representação da classe Concret no diagrama
/// </summary>
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.");
}
}
}
22 changes: 22 additions & 0 deletions 06 - Template Method/UsingPattern/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
8 changes: 8 additions & 0 deletions 06 - Template Method/UsingPattern/UsingPattern.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>