###Overview This repository explains key software design principles with real-life examples in C#.
Single Responsibility Principle (SRP)
A class should have only one reason to change.
Example: A paymentProcessor class should only process payments, while a separate transactionLogger class handles just the transaction logs.
Open/Closed Principle (OCP)
Classes should be open for extension but closed for modification.
Example: Use interfaces or abstract classes to allow new functionality without modifying existing code.
Liskov Substitution Principle (LSP)
Subtypes should be replaceable for their base types without breaking code.
Example: A TroyPayment and CreditCardPayment should work interchangeably when using a PaymentMethod base class.
Interface Segregation Principle (ISP)
Clients should not be forced to depend on interfaces they do not use.
Example: Instead of one ITrancaction interface with payment(), refund() split it into smaller interfaces like IPaymentMethod, IIRefundable.
Dependency Inversion Principle (DIP)
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Example: Use dependency injection instead of creating instances inside a class.
Avoid duplicating code by using functions, classes, or modules.
Example: Instead of duplicating validation logic, create a reusable CalculatePrice(int days, deciaml dailtyRate) method.
Write code that is simple, clear, and easy to understand.
Example: Prefer Dictionary<string, decimal> over switch cases.
Don't add features until you actually need them. Example: Don't add values to the function unlesss you have a use for them in it.
"Don't talk to strangers" – A class should only interact with its direct dependencies.
Example: A Cashier should call Barista.MakeCoffee(), not Barista.CoffeeMachine.BrewCoffee().
Favor using object composition instead of deep inheritance trees.
Example: A Car has an Engine object instead of extending a Vehicle class.