Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 0 additions & 15 deletions DesignPattnersImplementation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Visitor", "src\Visitor\Visi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interpreter", "src\Interpreter\Interpreter.csproj", "{AD8CE3D6-BA70-4D5D-82BB-B81D16D47586}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitOfWork", "src\UnitOfWork\UnitOfWork.csproj", "{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository", "src\Repository\Repository.csproj", "{88674B88-3569-4F93-9C73-FF52559A47B1}"
EndProject
Global
Expand Down Expand Up @@ -357,18 +355,6 @@ Global
{AD8CE3D6-BA70-4D5D-82BB-B81D16D47586}.Release|x64.Build.0 = Release|Any CPU
{AD8CE3D6-BA70-4D5D-82BB-B81D16D47586}.Release|x86.ActiveCfg = Release|Any CPU
{AD8CE3D6-BA70-4D5D-82BB-B81D16D47586}.Release|x86.Build.0 = Release|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Debug|x64.ActiveCfg = Debug|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Debug|x64.Build.0 = Debug|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Debug|x86.ActiveCfg = Debug|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Debug|x86.Build.0 = Debug|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Release|Any CPU.Build.0 = Release|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Release|x64.ActiveCfg = Release|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Release|x64.Build.0 = Release|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Release|x86.ActiveCfg = Release|Any CPU
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846}.Release|x86.Build.0 = Release|Any CPU
{88674B88-3569-4F93-9C73-FF52559A47B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88674B88-3569-4F93-9C73-FF52559A47B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88674B88-3569-4F93-9C73-FF52559A47B1}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -411,7 +397,6 @@ Global
{9C5CC585-85F4-4032-B8E2-03EBD02EFD1E} = {FBFC9E17-B858-4F85-A5EF-C2AE3C56544E}
{BEB1DEF9-C0A7-4A24-8D72-697F845D0421} = {FBFC9E17-B858-4F85-A5EF-C2AE3C56544E}
{AD8CE3D6-BA70-4D5D-82BB-B81D16D47586} = {FBFC9E17-B858-4F85-A5EF-C2AE3C56544E}
{33EBE2B3-4D5C-4D2B-A6C4-BDCC47C41846} = {FBFC9E17-B858-4F85-A5EF-C2AE3C56544E}
{88674B88-3569-4F93-9C73-FF52559A47B1} = {FBFC9E17-B858-4F85-A5EF-C2AE3C56544E}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ Crie esse repositório para ir explorar todos eles
- Iterator :white_check_mark:
- Visitor :white_check_mark:
- Interpreter :white_check_mark:
- **Enterprise (Infrastructure)**
- **Enterprise (Compartilha mesma pasta Repository)**
- Repository :white_check_mark:
- Unit of Work :white_check_mark:
166 changes: 166 additions & 0 deletions src/Interpreter/Implementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
namespace Interpreter
{
/// <summary>
/// Context
/// </summary>
public class RomanContext
{
public int Input { get; set; }
public string Output { get; set; } = string.Empty;

public RomanContext(int input)
{
Input = input;
}
}

/// <summary>
/// Abstraction expression
/// </summary>
public abstract class RomanExpression
{
public abstract void Interpret(RomanContext context);
}

//9 = IX
//8 = VIII
//7 = VII
//6 = VI
//5 = V
//4 = IV
//3 = III
//2 = II
//1 = I

//simplified - each combination is reachable with subscription and these 4:
//9 = IX
//5 = V
//4 = IV
//1 = I


/// <summary>
/// Terminal Expression
/// </summary>
public class RomanOneExpression : RomanExpression
{
public override void Interpret(RomanContext context)
{
while((context.Input - 9) >= 0)
{
context.Output += "IX";
context.Input -= 9;
}

while((context.Input - 5) >= 0)
{
context.Output += "V";
context.Input -= 5;
}

while((context.Input - 4) >= 0)
{
context.Output += "IV";
context.Input -= 4;
}

while((context.Input - 1) >= 0)
{
context.Output += "I";
context.Input -= 1;
}
}
}

//90 = XC
//80 = LIII
//70 = LII
//60 = LX
//50 = L
//40 = XL
//30 = XXX
//20 = XX
//10 = X

//simplified - each combination is reachable with subscription and these 4:
//90 = XC
//50 = L
//40 = XL
//10 = X

public class RomanTenExpression : RomanExpression
{
public override void Interpret(RomanContext context)
{
while ((context.Input - 90) >= 0)
{
context.Output += "XC";
context.Input -= 90;
}

while ((context.Input - 50) >= 0)
{
context.Output += "L";
context.Input -= 50;
}

while ((context.Input - 40) >= 0)
{
context.Output += "XL";
context.Input -= 40;
}

while ((context.Input - 10) >= 0)
{
context.Output += "X";
context.Input -= 10;
}
}
}

//900 = CM
//800 = DCCC
//700 = DCC
//600 = DC
//500 = D
//400 = CD
//300 = CCC
//200 = CC
//100 = C

//simplified - each combination is reachable with subscription and these 4:
//900 = CM
//500 = D
//400 = CD
//100 = C

public class RomanHundreExpression : RomanExpression
{
public override void Interpret(RomanContext context)
{
while ((context.Input - 900) >= 0)
{
context.Output += "CM";
context.Input -= 900;
}

while ((context.Input - 500) >= 0)
{
context.Output += "D";
context.Input -= 500;
}

while ((context.Input - 400) >= 0)
{
context.Output += "CD";
context.Input -= 400;
}

while ((context.Input - 100) >= 0)
{
context.Output += "C";
context.Input -= 100;
}
}
}
}
34 changes: 32 additions & 2 deletions src/Interpreter/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
using System;
using System.Collections.Generic;

namespace Interpreter;

class Program
static class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
var expressions = new List<RomanExpression>
{
new RomanHundreExpression(),
new RomanTenExpression(),
new RomanOneExpression()
};

var context = new RomanContext(5);
foreach (var expression in expressions)
{
expression.Interpret(context);
}

Console.WriteLine($"Translating Arabic numerals to Roman numerals: 5 {context.Output}");

context = new RomanContext(81);
foreach (var expression in expressions)
{
expression.Interpret(context);
}

Console.WriteLine($"Translating Arabic numerals to Roman numerals: 81 {context.Output}");

context = new RomanContext(733);
foreach (var expression in expressions)
{
expression.Interpret(context);
}

Console.WriteLine($"Translating Arabic numerals to Roman numerals: 733 {context.Output}");
}
}
40 changes: 40 additions & 0 deletions src/Repository/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore;
using Repository.Entities;

namespace Repository.Data
{
public class AppDbContext : DbContext
{
public DbSet<Product> Products => Set<Product>();
public DbSet<Category> Categories => Set<Category>();

public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Product>(entity =>
{
entity.HasKey(x => x.Id);

entity.Property(x => x.Name)
.HasMaxLength(150)
.IsRequired();

entity.Property(x => x.Price)
.HasPrecision(10, 2);
});

modelBuilder.Entity<Category>(entity =>
{
entity.HasKey(x => x.Id);

entity.Property(x => x.Name)
.HasMaxLength(150)
.IsRequired();
});
}
}
}
13 changes: 13 additions & 0 deletions src/Repository/Entities/Category.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Repository.Entities
{
public class Category
{
public Guid Id { get; set; }

public string Name { get; set; } = string.Empty;

public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}
}
15 changes: 15 additions & 0 deletions src/Repository/Entities/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Repository.Entities
{
public class Product
{
public Guid Id { get; set; }

public string Name { get; set; } = string.Empty;

public decimal Price { get; set; }

public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}
}
Loading
Loading