Skip to content

Commit

Permalink
Decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 13, 2021
1 parent 46c1012 commit 1274bed
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 0 deletions.
20 changes: 20 additions & 0 deletions PatternsEstruturais/Decorator/Decorator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace Decorator
{
//É o Decorador Abstrato
public class Decorator : ItemBiblioteca
{
protected ItemBiblioteca itemBiblioteca { get; set; }

public Decorator(ItemBiblioteca itemBiblioteca)
{
this.itemBiblioteca = itemBiblioteca;
}

public override void Exibe()
{
this.itemBiblioteca.Exibe();
}
}
}
8 changes: 8 additions & 0 deletions PatternsEstruturais/Decorator/Decorator.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>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
36 changes: 36 additions & 0 deletions PatternsEstruturais/Decorator/Emprestado.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;

namespace Decorator
{
//É o Decorador Concreto
public class Emprestado : Decorator
{
protected List<string> emprestados = new List<string>();

public Emprestado(ItemBiblioteca itemBiblioteca) : base(itemBiblioteca)
{
}

public void EmprestarItem(string nome)
{
this.emprestados.Add(nome);
this.itemBiblioteca.NumeroCopias--;
}

public void DevolverItem(string nome)
{
this.emprestados.Remove(nome);
this.itemBiblioteca.NumeroCopias++;
}

public override void Exibe()
{
base.Exibe();
foreach (string item in this.emprestados)
{
Console.WriteLine($"Emprestado: {item}");
}
}
}
}
11 changes: 11 additions & 0 deletions PatternsEstruturais/Decorator/ItemBiblioteca.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Decorator
{
public abstract class ItemBiblioteca
{
public int NumeroCopias { get; set; }

public abstract void Exibe();
}
}
25 changes: 25 additions & 0 deletions PatternsEstruturais/Decorator/Livro.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace Decorator
{
public class Livro : ItemBiblioteca
{
public string Autor { get; set; }
public string Titulo { get; set; }

public Livro(string autor, string titulo, int numeroCopias)
{
this.Autor = autor;
this.Titulo = titulo;
this.NumeroCopias = numeroCopias;
}

public override void Exibe()
{
Console.WriteLine("\nLivro ----");
Console.WriteLine($" Autor: {this.Autor}");
Console.WriteLine($" Titulo: {this.Titulo}");
Console.WriteLine($" #Cópias: {this.NumeroCopias}");
}
}
}
28 changes: 28 additions & 0 deletions PatternsEstruturais/Decorator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace Decorator
{
class Program
{
static void Main(string[] args)
{
Livro livro = new Livro(autor: "João", titulo: "João e o pé de Feijão", numeroCopias: 10);
livro.Exibe();

Video video = new Video(diretor: "Rodrigo", titulo: "Aulas avançadas", minutosDuracao: 25, numeroCopias: 3);
video.Exibe();

Console.WriteLine("\nEmprestando um Vídeo:");

Emprestado emprestado = new Emprestado(video);
emprestado.EmprestarItem("Carlos");
emprestado.EmprestarItem("Maria");

emprestado.Exibe();

emprestado.DevolverItem("Carlos");

emprestado.Exibe();
}
}
}
32 changes: 32 additions & 0 deletions PatternsEstruturais/Decorator/Video.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
public class Video : ItemBiblioteca
{
public Video(string diretor, string titulo, int minutosDuracao, int numeroCopias)
{
this.Diretor = diretor;
this.Titulo = titulo;
this.MinutosDuracao = minutosDuracao;
this.NumeroCopias = numeroCopias;
}

public string Diretor { get; set; }
public string Titulo { get; set; }
public int MinutosDuracao { get; set; }



public override void Exibe()
{
Console.WriteLine("\nVídeo ----");
Console.WriteLine($" Diretor: {this.Diretor}");
Console.WriteLine($" Titulo: {this.Titulo}");
Console.WriteLine($" Duração: {this.MinutosDuracao}");
Console.WriteLine($" #Cópias: {this.NumeroCopias}");
}
}
}
6 changes: 6 additions & 0 deletions PatternsEstruturais/PatternsEstruturais.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bridge", "Bridge\Bridge.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Composite", "Composite\Composite.csproj", "{45CCBC20-6C3E-4903-994D-149446B2F51A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decorator", "Decorator\Decorator.csproj", "{A1691928-5028-4FF7-8BEC-CAC23E760596}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{45CCBC20-6C3E-4903-994D-149446B2F51A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45CCBC20-6C3E-4903-994D-149446B2F51A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45CCBC20-6C3E-4903-994D-149446B2F51A}.Release|Any CPU.Build.0 = Release|Any CPU
{A1691928-5028-4FF7-8BEC-CAC23E760596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1691928-5028-4FF7-8BEC-CAC23E760596}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1691928-5028-4FF7-8BEC-CAC23E760596}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1691928-5028-4FF7-8BEC-CAC23E760596}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 1274bed

Please sign in to comment.