Skip to content

Instantly share code, notes, and snippets.

View ThiagoBarradas's full-sized avatar
👽
em marte!

Thiago Barradas ThiagoBarradas

👽
em marte!
View GitHub Profile
@ThiagoBarradas
ThiagoBarradas / solid-I-interfaces-example-3.cs
Last active June 8, 2023 20:07
SOLID [I] - Interface Example with segmented behavior
public interface ITalkative
{
void Speak(string message);
}
public interface IMovable
{
void Move(long x, long y, long z);
}
@ThiagoBarradas
ThiagoBarradas / solid-I-interfaces-example-2.cs
Last active March 1, 2021 02:11
SOLID [I] - Interfaces Example with Inheritance
public interface IMovable
{
void Move(long x, long y, long z);
}
public interface IHuman : IMovable
{
string Name { get; set; }
string Document { get; set; }
@ThiagoBarradas
ThiagoBarradas / solid-I-interface-example-1.cs
Last active March 1, 2021 01:37
SOLID [I] - Interface Example 1
public interface IHuman
{
string Name { get; set; }
string Document { get; set; }
long Age { get; set; }
void Move(long x, long y, long z);
@ThiagoBarradas
ThiagoBarradas / solid-L-wrong-abstraction.cs
Created January 24, 2021 16:05
SOLID [L] Wrong Abstraction
public class Transaction
{
public virtual long OriginalAmount { get; set; }
public virtual long InterestAmount { get; set; }
}
public class CreditCardTransaction : Transaction
{
}
@ThiagoBarradas
ThiagoBarradas / solid-L-correct-implementation.cs
Last active January 24, 2021 15:58
SOLID [L] - Correct Implementation
public abstract class Transaction
{
public long OriginalAmount { get; set; }
public virtual long GetTotalPaid()
{
return this.OriginalAmount;
}
}
@ThiagoBarradas
ThiagoBarradas / solid-L-wrong-method.cs
Last active January 24, 2021 16:02
SOLID [L] - Wrong Method
public abstract class Transaction
{
public long OriginalAmount { get; set; }
}
public class CreditCardTransaction : Transaction
{
public long InterestAmount { get; set; }
}
@ThiagoBarradas
ThiagoBarradas / solid-O-deciding-implementations.cs
Created January 10, 2021 00:45
SOLID [O] - Deciding implementations
// sample enum for payment.Type
public enum PaymentType
{
CreditCard,
DebitCard,
BankInvoice,
Pix
}
// simple factory
@ThiagoBarradas
ThiagoBarradas / solid-O-wrong-method.cs
Last active January 9, 2021 23:53
SOLID [S] - Wrong Method
public class PaymentService
{
public Payment ProcessPayment(Payment payment)
{
if (payment.Type == "credit_card")
{
// proccess payment with credit card
}
else if (payment.Type == "debit_card")
{
@ThiagoBarradas
ThiagoBarradas / solid-S-splitting-class.cs
Last active June 8, 2023 21:10
SOLID [S] - Splitting class (Class with SRP)
public class PaymentService : IPaymentService
{
private readonly IPaymentRepository PaymentRepository;
private readonly INotificationService NotificationService;
private readonly IBankService BankService;
public PaymentService(
IPaymentRepository paymentRepository,
@ThiagoBarradas
ThiagoBarradas / solid-S-extracting-method.cs
Last active January 14, 2021 19:50
SOLID [S] - Extracting Method (Method with SRP) but with wrong class structure
public class PaymentService
{
// ctors
// properties
// etc
public Payment ProcessPayment(Payment payment)
{
var transaction = this.BankService.CreateTransaction(payment);