 Good morning guys. I hope everyone is doing great. So we'll come back to our channel today We are here with one more important interview question. That is what our solid principles This is a mandatory interview question if you are an experienced candidate and if you are unable to answer this question 99.9 percent There are chances that you will get rejected. I Because this is my personal experience like A few years back like when I was having just 1.5 or 2 and a half years experience I thought of switching and I was used to like me and my friends used to attend interviews So every interview I used to face this question what are solid principles? So I never used to answer. I directly used to say we thought wasting time I don't know what are solid principles and I was used to give more importance even while I was preparing I used to give more importance to coding questions collections and all those things Comparative comparable and all those things exceptions. So this part I was more concentrated rather than Theorety theory because this is a theoretical question. So I always used to get rejected So as time passed all my friends moved out of my company and I was the only guy stuck. So I Was attending one interview with one of the product-based company I don't want to reveal the name and in that interview again I was face this question. I face this question the first round first question Like what are solid principles? So I was unable to answer. I directly said without hesitating I don't know what are solid principles and that guy looked a stunning Reaction he gave me and he continued with other questions. So like 10 to 12 questions He asked me I was able to answer all the questions and I was not able to answer this and this was happening with me All the interview. So I asked him so why solid principles are given that much importance. So he said Okay, Ravi, how you in your current project? How many classes are there? So I said more than 100 and how many packages I said like 10 like more than 10 to 12 packages are there 10 15 packages are there and then asked me certain other things How many proper XMLs are there property files are there all those things? so When I answered him so he said me so can't we write all the logic inside a controller itself whenever a request comes I will have all the logic in one class only so I He said me like can't we have so I said we can have everything because Java don't restrict us We can have everything inside some single class. It's a two entire application in one single class, right? So I said I was in bit dilemma. Yes, we can have then why then he asked me Why don't we have like that? So I said whenever we don't know anything like at that time we used to say it's a standard that has been defined in the project So I said the same thing. That's the standard. We'll say he laughed and said You go back home and you Google it. Why are we having different classes different packages interfaces? code structure in that way and you will end up Learning solid principles. So I came back and There at that point I learned Solid principles. So just wanted to share this experience. So shade So coming to the question. What are solid principles? The term solid is an acronium our five design principles intended to make software designs more understandable flexible and Maintainable solid principles are The design principles that enables us to manage the software design problems So basically solid is nothing but like so lady is an acronium of five different things So it stands for single responsibility principle or SRP. You can say O stands for open closed principle or OSP L stands for list code substitution principle LSP I stands for interface segregation principle IS D for dependency inversion principle So these are the five principles that helps us a lot while developing a project or any class So in the end, I will be answering like how I answer this question now So don't wish that section as well. So what are the advantages that we get using solid principles? So we can achieve a reduction in complexity of code With the solid principle reduce tight coupling. We can avoid the tight coupling here Reduce error and implement a reusability here. So we can reuse the code increase the readability Extensibility and maintenance achieve better testability. So these are the few advantages that I feel we get So coming to the first Principle That is single responsibility principle Like this is a bookish definition. You can say a class should have only one reason to change So this is a bookish knowledge a definition of SRP. That is single principle Single responsibility principle every modular class should have responsibility over a single part of the functionality provided by the software and That responsibility should be entirely encapsulated by the class. So this is about the single Responsibility principle and mostly a class should be designed in such a way that it only hand is Particular or only one functionality related things. You cannot include different things in inside the same class So that violates SRP if you are doing that. So next is l alpha Discourse substitution principle So objects in a program should be repressible with the instance of their subtypes without altering the correct Correctness of the program. So this is the definition What it means is if a program or a model is a base class Then the reference of the big base class can be replaced with the derived class without affecting the functionality of the program module We can also state that derived right must be substitutable for the base types So that is the scope substitution principle it for Generally in simple words if at all you want to put it So base type class can hold child class reference without having a huge impact on the application So that should that is how we need to Provide the implementation the third is open closed principle which is software entities should be open for extension But closed for modification So the design and the writing of the code should be in such a way Should be done in such a way that the new functionality should be added with the minimal changes to the existing code Or you can say it as the design should be Uh, the design should be in a way to allow the adding of a new functionality as a new classes Keeping as much as possible existing code unchanged So why is that why do we need that is? Because our existing classes should be closed for modification if at all we are changing the existing classes uh What I can say frequently there are high chances that we we may introduce new bugs only if at all we want to fix the bugs Then only we should modify the existing classes the next phase interface segregation principle so What it states is Clients should not be forced to depend upon interface that they don't want to use so This is the definition We should not enforce clients to implement interfaces that they don't choose instead of creating one big interface We can break down it into smaller interfaces so here Instead of having only one we should segregate a interface in such a way that The class that is implementing that interface should should provide the functionality It should not be like uh, uh, necessarily we have to overwrite some method and retaining null from it We should not do that So instead of that we should segregate the interface proper the next and the last thing is dependency inversion principle That says depend on abstraction not on concretions Abstractions should not depend on the details whereas details should depend on abstraction. So this is the last and final Uh principle that is we have to depend on the abstractions So this way the five solid principles So coming to the question like how I answer So this is how I answer Basically solid principles acts as guidelines to developers while designing the class or project Solid is an acronym for five different principles. That is s for single responsibility O for open close principle l for list course principle i for interface segregation and d for dependency inversion While designing class, we should make sure that each class should have Only one functionality related code a class should be open for extension But close for modification, which is second principle Liscope substitution principle states that the parent class can hold child class reference without having any issues in the code Interface segregation states that we should not make a class to implement unnecessary interfaces and And dependency inversion means we should depend on abstraction rather than concretion So this is how I answer within a minute And after that There will be cross-questions on this as well like very exactly given example where exactly you have used uh Liscope substitution principle. So Uh You have to give you have to explain if at all you have used liscope substitution principle and believe me 99.9 projects use all this principle It's just you need to find where exactly you have used what and There might be a question that have you ever seen a code violating This principles. Yes, you might have seen like At least I have seen there are many classes that implement interfaces and in the method that they override They simply write one logger. This method will never be called from this class So that is breaking of the principle when we don't need that method. Why are we implementing that interface? We haven't segregated our Interface properly there and there are chances that you might see uh The classes especially uh Well, suppose a validation class is that it's a primary its complete function should be validating upon some employee object Suppose it should validate only employee object Instead of that, you might see it might be sending email also upon validating It might send an email to something or it might do a db instead of operation So that is wrong. So these are the places like where we violate solid principles So that is this That is it from this video like about solid principle. So I hope if you have liked the video You can subscribe All right Subscribe if you haven't subscribed the channel you can subscribe If you feel if we this is a beneficial you can like the video you can share this video to other technical platforms to help others Or if you have any feedback you can comment it out in the comment section as well So that is about this video and if you are on our channel for the first time And if you have a question like who are we and what we do? So we have basically a bunch of software engineers who attend interviews with different mns And share our real-time interview Experiences through these videos if you want to share us your interview experience You can mail your experience at the email ID that is given in the description Apart from that or you can visit our channel and see The number of like more than 100 interview experiences We have already shared and I personally feel that that is really helpful to a lot of people because like daily we get 10s mail like more than 10 15 miss saying like thank you miss that our channel is helping At least a few people I have we really feel very happy when we see that kind of miss because the intention was that to help people And if you liked it if you haven't subscribed it Just subscribe the channel because there are many videos that are there in the queue as we are not getting time We are not preparing more videos And Thank you for watching