filmov
tv
Open Closed Principle Tutorial with Java Coding Example for Beginners
Показать описание
Open-closed principle is the second principle of SOLID principles. Open-closed principle states that Software entities like classes, modules, functions, etc. should be open for extension, but closed for modification.
In software development, the use of object-oriented design with solid principles is crucial. It helps to write flexible, scalable, and reusable code. It is recommended that the developers follow SOLID principles when writing a code.
Robert C. Martin considered this principle as the “the most important principle of object-oriented design”. But he wasn’t the first one who defined it. Bertrand Meyer wrote about it in 1988 in his book Object-Oriented Software Construction. He explained the Open/Closed Principle.
Don't be mistaken the phrase "open for extension" with inheritance because inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class. because if the superclass changes, then subclasses may need to be modified. creating a class or software entities whose behaviour can be changed without the need to edit and recompile the code itself. Hence inheritance doesn't meet this requirement because inheritance is compile time polymorphism and introduce the tight coupling with parent class.
The main benefit of this approach is that an interface introduces an additional level of abstraction which enables loose coupling instead of tight coupling we experience with inheritance. The implementations of an interface are independent of each other and don’t need to share any code.
Another way to achieve Open-Closed Principle is through compositional design patterns like we see in the Strategy design pattern.
** Benefits of Open-Closed Principle **
1. Open-Closed principle allows multiple implementations of the same algorithm.
2. Open-Closed principle using interface removes tight coupling between parent and child classes.
3. Open-Closed principle allow to add new feature without modifying existing code.
4. Open-Closed principle introduce loose coupling between software components.
** Chapter Timestamps **
0:00 Welcome to Open-Closed Principle
1:07 Agenda of Open Closed Principle Tutorial
2:13 Introduction to Open Closed Principle
5:38 Real World Example of Open Closed Principle
7:01 Java Code Example of Open Closed Principle
13:04 Usage of Open Closed Principle
13:53 Advantages of Open Closed Principle
14:30 Summary of Open Closed Principle
15:20 Next Video on Liskov Substitution Principle
#solidprinciples #openclosed #openclosedprinciple
** GIT Repository **
** CHECK OUT OUR OTHER VIDEOS **
** CHECK OUR PLAYLISTS **
Docker Containers Complete Tutorial
** Acronyms **
OOP – Object Oriented Programming Languages
SRP – Single Responsibility Principle
OCP – Open Closed Principle
LSP – Liskov Substitution Principle
ISP – Interface Segregation Principle
DIP – Dependency Inversion Principle
COD – Code One Digest
** ABOUT OUR CHANNEL **
CodeOneDigest is a youtube channel that produces videos on programming languages, cloud and container technologies, Software design principles, Java frameworks in English and Hindi languages.
Check out our channel here:
Don’t forget to subscribe!
** OUR WEBSITE **
** GET IN TOUCH **
FOLLOW US ON SOCIAL - LIKE, SHARE & SUBSCRIBE
Get updates or reach out to Get updates on our Social Media Profiles!
In software development, the use of object-oriented design with solid principles is crucial. It helps to write flexible, scalable, and reusable code. It is recommended that the developers follow SOLID principles when writing a code.
Robert C. Martin considered this principle as the “the most important principle of object-oriented design”. But he wasn’t the first one who defined it. Bertrand Meyer wrote about it in 1988 in his book Object-Oriented Software Construction. He explained the Open/Closed Principle.
Don't be mistaken the phrase "open for extension" with inheritance because inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class. because if the superclass changes, then subclasses may need to be modified. creating a class or software entities whose behaviour can be changed without the need to edit and recompile the code itself. Hence inheritance doesn't meet this requirement because inheritance is compile time polymorphism and introduce the tight coupling with parent class.
The main benefit of this approach is that an interface introduces an additional level of abstraction which enables loose coupling instead of tight coupling we experience with inheritance. The implementations of an interface are independent of each other and don’t need to share any code.
Another way to achieve Open-Closed Principle is through compositional design patterns like we see in the Strategy design pattern.
** Benefits of Open-Closed Principle **
1. Open-Closed principle allows multiple implementations of the same algorithm.
2. Open-Closed principle using interface removes tight coupling between parent and child classes.
3. Open-Closed principle allow to add new feature without modifying existing code.
4. Open-Closed principle introduce loose coupling between software components.
** Chapter Timestamps **
0:00 Welcome to Open-Closed Principle
1:07 Agenda of Open Closed Principle Tutorial
2:13 Introduction to Open Closed Principle
5:38 Real World Example of Open Closed Principle
7:01 Java Code Example of Open Closed Principle
13:04 Usage of Open Closed Principle
13:53 Advantages of Open Closed Principle
14:30 Summary of Open Closed Principle
15:20 Next Video on Liskov Substitution Principle
#solidprinciples #openclosed #openclosedprinciple
** GIT Repository **
** CHECK OUT OUR OTHER VIDEOS **
** CHECK OUR PLAYLISTS **
Docker Containers Complete Tutorial
** Acronyms **
OOP – Object Oriented Programming Languages
SRP – Single Responsibility Principle
OCP – Open Closed Principle
LSP – Liskov Substitution Principle
ISP – Interface Segregation Principle
DIP – Dependency Inversion Principle
COD – Code One Digest
** ABOUT OUR CHANNEL **
CodeOneDigest is a youtube channel that produces videos on programming languages, cloud and container technologies, Software design principles, Java frameworks in English and Hindi languages.
Check out our channel here:
Don’t forget to subscribe!
** OUR WEBSITE **
** GET IN TOUCH **
FOLLOW US ON SOCIAL - LIKE, SHARE & SUBSCRIBE
Get updates or reach out to Get updates on our Social Media Profiles!
Комментарии