
Meet Arjun Thakur in this introduction to solid principles for Java, covering five principles—single responsibility, open-closed, Liskov substitution, interface segregation, and dependency inversion—and applying them through hands-on coding.
Apply the interface segregation principle by splitting a large plant interface into smaller interfaces: growing, flowering, and fruiting. This creates reusable, modular code in Java and avoids bloated implementations.
Apply the dependency inversion principle by introducing an email service interface that Gmail and Outlook implement, enabling the user service to swap in X mail service without changes.
Learn the SOLID principles of object-oriented programming (OOP) from a former Amazon engineer. This course covers all five principles in detail, with live code examples, pros and cons.
The SOLID principles are:
Single Responsibility Principle (SRP): Each class should have a single responsibility, and that responsibility should be completely encapsulated by the class.
Live code example: You will see a live code example of a class that follows the SRP, and a live code example of a class that does not follow the SRP. You will also see the pros and cons of each approach.
Open/Closed Principle (OCP): Classes should be open for extension, but closed for modification. This means that you should be able to add new functionality to your code without having to modify existing code.
Live code example: You will see a live code example of a class that follows the OCP, and a live code example of a class that does not follow the OCP. You will also see the pros and cons of each approach.
Liskov Substitution Principle (LSP): Subtypes should be substitutable for their base types without breaking the program. This means that you should be able to use a subtype anywhere you would use a base type, without any unexpected behavior.
Live code example: You will see a live code example of a class that follows the LSP, and a live code example of a class that does not follow the LSP. You will also see the pros and cons of each approach.
Interface Segregation Principle (ISP): Interfaces should be small and specific, so that they can be easily reused and combined.
Live code example: You will see a live code example of an interface that follows the ISP, and a live code example of an interface that does not follow the ISP. You will also see the pros and cons of each approach.
Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions. This makes your code more decoupled and easier to test and maintain.
Live code example: You will see a live code example of a class that follows the DIP, and a live code example of a class that does not follow the DIP. You will also see the pros and cons of each approach.