forked from LucasCancio/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46c1012
commit 1274bed
Showing
8 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters