Skip to content

govardhansbhati/SOLID-Principles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SOLID Principles in Swift ๐Ÿš€

This repository contains detailed explanations and Swift Playground code examples demonstrating the SOLID principles of object-oriented design.

๐Ÿ“Œ What is SOLID?

SOLID is a set of five design principles that help create maintainable, scalable, and flexible software.

1๏ธโƒฃ S - Single Responsibility Principle (SRP) "A class should have only one reason to change."

โœ… Ensures each class has only one responsibility. ๐Ÿ›  Example: Separating report generation from report printing.

2๏ธโƒฃ O - Open/Closed Principle (OCP) "Software entities should be open for extension but closed for modification."

โœ… New functionality should be added without modifying existing code. ๐Ÿ›  Example: Using protocols to add new discount types without changing the core logic.

3๏ธโƒฃ L - Liskov Substitution Principle (LSP) "Objects of a superclass should be replaceable with objects of a subclass without breaking the system."

โœ… A subclass should never break the behavior of its superclass. ๐Ÿ›  Example: Avoiding a Penguin subclass that overrides fly() incorrectly.

4๏ธโƒฃ I - Interface Segregation Principle (ISP) "A class should not be forced to implement interfaces it does not use."

โœ… Interfaces should be small and focused. ๐Ÿ›  Example: Splitting a Worker protocol into Workable and Eatable.

5๏ธโƒฃ D - Dependency Inversion Principle (DIP) "High-level modules should not depend on low-level modules. Both should depend on abstractions."

โœ… Depend on protocols instead of concrete implementations. ๐Ÿ›  Example: Using Notifier protocol instead of directly depending on EmailNotifier.

About

This repository showcases clean and practical examples of the SOLID principles in swift programming.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages