Skip to content

Instantly share code, notes, and snippets.

Avatar
👽
em marte!

Thiago Barradas ThiagoBarradas

👽
em marte!
View GitHub Profile
@ThiagoBarradas
ThiagoBarradas / solid-I-interfaces-example-4.cs
Created Mar 1, 2021
SOLID [I] - Interface Example with and without Inheritance
View solid-I-interfaces-example-4.cs
public interface IBomb
{
void Explode();
}
public interface IHuman
{
string Name { get; set; }
string Document { get; set; }
@ThiagoBarradas
ThiagoBarradas / solid-I-interfaces-example-3.cs
Created Mar 1, 2021
SOLID [I] - Interface Example with segmented behavior
View solid-I-interfaces-example-3.cs
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 Mar 1, 2021
SOLID [I] - Interfaces Example with Inheritance
View solid-I-interfaces-example-2.cs
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 Mar 1, 2021
SOLID [I] - Interface Example 1
View solid-I-interface-example-1.cs
public interface IHuman
{
string Name { get; set; }
string Document { get; set; }
long Age { get; set; }
void Move(long x, long y, long z);
View solid-L-wrong-abstraction.cs
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 Jan 24, 2021
SOLID [L] - Correct Implementation
View solid-L-correct-implementation.cs
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 Jan 24, 2021
SOLID [L] - Wrong Method
View solid-L-wrong-method.cs
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 Jan 10, 2021
SOLID [O] - Deciding implementations
View solid-O-deciding-implementations.cs
// sample enum for payment.Type
public enum PaymentType
{
CreditCard,
DebitCard,
BankInvoice,
Pix
}
// simple factory
@ThiagoBarradas
ThiagoBarradas / solid-O-wrong-method.cs
Last active Jan 9, 2021
SOLID [S] - Wrong Method
View solid-O-wrong-method.cs
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 Jan 14, 2021
SOLID [S] - Splitting class (Class with SRP)
View solid-S-splitting-class.cs
public class PaymentService : IPaymentService
{
private readonly IPaymentRepository PaymentRepository;
private readonly INotificationService NotificationService;
private readonly IBankService BankService;
public PaymentService(IPaymentRepository paymentRepository, INotificationService notificationService, IBankService bankService)
{