Make Your Code Clean With the SOLID Principles

Поділитися
Вставка
  • Опубліковано 7 лют 2025
  • Writing clean code gets more and more essential the bigger your projects get. The SOLID principles help you do that.
    ⭐ Get certificates for your future job
    ⭐ Save countless hours of time
    ⭐ 100% money back guarantee for 30 days
    ⭐ Become a professional Android developer now:
    pl-coding.com/...
    💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
    elopage.com/s/...
    🎓 Become an industry-ready developer in the Mobile Dev Campus:
    pl-coding.com/...
    🎁 Get my FREE 4.5h course "The Best Practice Guide to Android Architecture":
    pl-coding.com/...
    Read our weekly Android blog:
    pl-coding.com/...
    Regular programming advice on my Instagram page: / _philipplackner_
    Checkout my GitHub: github.com/phi...
    You like my free content? Here you can buy me a coffee:
    www.buymeacoff...

КОМЕНТАРІ • 242

  • @iamkrishn
    @iamkrishn 3 роки тому +173

    0:00 Introduction
    0:51 Find problem with existing code
    1:36 S = Single Responsibility Principle
    4:05 O = Open Extensions, Closed Modifications
    7:09 L = Liskov Substitution
    9:43 I = Interface Segregation
    11:31 D = Dependency Inversion
    Great explanation with a simple to understand example. Amazing videos as always.

  • @aimenham4685
    @aimenham4685 3 роки тому +30

    finally , now i understand why interfaces are so important ,I struggled so much to find reason to use them , Thank you philipp

    • @adipurnomo5683
      @adipurnomo5683 2 роки тому

      Same here

    • @9iht6ihgt43rzhijj
      @9iht6ihgt43rzhijj Рік тому +1

      Me too... I knew what an interface is in general, but not what it really means in coding (at least I had a bright moment)...

  • @SlakySlaky
    @SlakySlaky 3 роки тому +125

    Play the video in 2x speed then you'll be learning SOLID in 10 minutes

    • @feepin2058
      @feepin2058 3 роки тому +11

      But you will understand 2x less as well

    • @CybercoderNaj
      @CybercoderNaj 3 роки тому +2

      @@feepin2058 not necessarily

    • @MateusMeurer
      @MateusMeurer 3 роки тому

      Lmao

    • @newbiegameplayy
      @newbiegameplayy 3 роки тому

      So scary 😂

    • @rahulmatte6621
      @rahulmatte6621 3 роки тому +2

      Writing code is simple but writing simple code is difficult. Good work Philip, it helped me to learn SOLID principles 😅

  • @devgabriel6898
    @devgabriel6898 2 роки тому +7

    Experience is so freaking important!.
    6 months ago, i saw this video i didnt understand anything of it.
    Now i understand everything! Because without knowing, i used all of this on my job, day to day on Android.
    Excelent!
    Now going for theory behind design patterns

  • @sergeisalnikov6427
    @sergeisalnikov6427 3 роки тому +1

    Hi!) I am from Russia and I am learning English to find a job in another country. You have good English I understand almost everything and your videos help me to learn the language))

  • @ani-eg8dy
    @ani-eg8dy 3 роки тому

    This is simple AF , nobody showed this important principle with this level of simple and easy examples ! Take a bow @Philipp

  • @Alchemist10241
    @Alchemist10241 3 роки тому +52

    For Interface segregation principle; I think we shouldn't create a function (that sometimes needed and sometimes not) - printLogs() function in this video - inside the same interface, We should create another interface and declare this function in it and if we need this functionality we can implement this interface and plus other interfaces like FileLogger interface in this video

    • @joanmedia
      @joanmedia 2 роки тому +3

      Agree! But the video still is amazing.

    • @aliahmadabadiha3263
      @aliahmadabadiha3263 2 роки тому

      You're right

    • @TheMohit987
      @TheMohit987 2 роки тому +1

      That's what I thought. Apart from that, video was good.

    • @ltadeu61
      @ltadeu61 2 роки тому +1

      Yeah! I did note that and agree with your response!

    • @diegohkdfln
      @diegohkdfln 9 місяців тому

      Also agree. If I have an instance of FileLogger and call printLogs(), I'd expect it to print the logs, but it won't. Moving the printLogs() to a separate interface such as LogPrinter, would make more sense.

  • @vonn9737
    @vonn9737 2 роки тому +13

    In example for open/closed, you treated the FileLogger class as being completely closed. Your CustomFileLogger was effectively another implementation of a FileLogger interface. It is ok to add new functionality to the FileLogger class, for example adding another function called timestampedError(), as long as you do not change the logError() function it adheres to the open/closed principle. All existing consumers of FileLogger will work exactly as they did before.
    For your example of Liskov substitution, the CustomErrorLogger class does not violate Liskov substitution. All instances of FileLogger can be replaced with CustomErrorLogger and will work exactly the same. This is because all calls to logError() will still go to the base FileLogger via inheritance.

    • @avigneswaranwaran
      @avigneswaranwaran 2 роки тому +1

      Your explanation is great. But, I have a question here, we already have a function named logError() in class FileLogger. So if we add timestampedError() to FileLogger it is not violating single resposibility principle? Kindly help me understand better

    • @stevebroshar3143
      @stevebroshar3143 Рік тому

      @@avigneswaranwaran well ... first of all timestampedError is not a good function name IMO. I follow the pattern of naming a function with a verb prefix. That, plus vonn didn't say what that function does makes it hard to know what vonn intends that function to do. But ... if that function is about logging to a file (logs a timestamped error?) then it does adhere to single responsibility (SR). Then again, vonn's comment is about Open/Closed (O/C) ... why are you asking about SR?

  • @saul5x
    @saul5x 7 місяців тому

    Thank you for your content Philipp! It helps so much and I'm glad there are developers who strive to make code as good as possible!

  • @tgamings1
    @tgamings1 9 місяців тому

    Vielen vielen Dank lieber Philipp für diese tolle Erklärung. Du hast da wirklich ein Talent solche Dinge sehr einfach für jeden verständlich zu machen.
    Liebe Grüße aus Österreich.

  • @alwaysbrillant10
    @alwaysbrillant10 2 роки тому

    Been binge watching all your recent videos. Amazing Android content 👏🏽 👌🏽

  • @CybercoderNaj
    @CybercoderNaj 3 роки тому +10

    I got goosebumps when he said, "This changes the entire implementation in one line of code. 🦋"

  • @also_david
    @also_david 2 роки тому

    awesome man. I didn' like you previously when seen on interviews but Now addicted to how you teach and how humble you really are.

  • @cesarlabastida1392
    @cesarlabastida1392 Рік тому

    You have such a nice way of explaining things brother. Keep making these videos please. Thank you.

  • @Andrei1889
    @Andrei1889 Рік тому

    I would've killed for this video when I first started learning Android and programming; Thank you.

  • @Chintanparmar
    @Chintanparmar 3 роки тому +1

    The video we didn't ask for, but really needed..

  • @kobeissi721
    @kobeissi721 3 роки тому +8

    For the optional interface function, you could also do = Unit instead of the empty function braces.

    • @PhilippLackner
      @PhilippLackner  3 роки тому +1

      Yea sure was just a quick demo here

    • @BilalBerek-tl3tq
      @BilalBerek-tl3tq 11 місяців тому +1

      @@PhilippLackner I think you must do make separate interfaces for every method. So you can use multiple inheritance for every method you need. Because function with empty body standing in the interface not a good case that much.

  • @Coldalecs
    @Coldalecs 3 роки тому

    I finally understand them now, I faced the same problem when searching them online...very hard to understand. This was waaay easier to understand. Thank you!

  • @masti437
    @masti437 2 роки тому

    I watched this video after watching your multi module course. So clearly explained .. I clearly understand why you inject abstractions using hilt instead of concrete implementation ..... Thank you so much Philip

  • @sakhti007
    @sakhti007 3 роки тому

    Thankyou Philipp, your way of explaining the issues through examples is just amazing. Thankyou for this great video.

  • @mustaqode_6617
    @mustaqode_6617 3 роки тому +28

    This is a most important video in the internet for devs today. It's not easy to explain this topic the way he did. Kudos @Philipp

  • @vitorferreira5464
    @vitorferreira5464 11 місяців тому

    Best video about SOLID I've ever seen

  • @TripDude
    @TripDude 2 роки тому +1

    Thanks for the explanations with easy examples 👌👏

  • @niranz7745
    @niranz7745 3 роки тому

    This is literally one of the best channels out there. I can’t believe that I only found it now. I love the videos. Keep them coming!
    P.s- would love to see a video about Alarm manager in Kotlin! Looking for such a video for a while.

  • @razidwa852
    @razidwa852 2 роки тому

    The best explanation I have ever seen. Great job

  • @mahdizareei4575
    @mahdizareei4575 3 роки тому

    Thank you so much dear philipp for record this courses ,
    I just wanted say i love you ❤️😘

  • @shantanubopardikar7719
    @shantanubopardikar7719 2 роки тому

    Bro, you are my new superhero, much much better than any other fictional superhero

  • @pratikpattanaik
    @pratikpattanaik 2 роки тому +10

    I think a more appropriate example of Liskov substitution principle would be if an overriden function were to do something unexpected and contrary to its implementation in the base class. This can be shown with a base function that changes the state of the class which is overriden by a function that doesn't call the super method. The example provided doesn't break this principle. I liked the other explanations.

  • @bjugdbjk
    @bjugdbjk 3 роки тому +2

    This is by far the best SOLID video explaining these complex SOLID software principles !! Thank you for this amazing content !!

  • @tinycontractor
    @tinycontractor 2 роки тому

    The thing that I liked about the video was not wasting my time to learn this SOLID buillshit. Thanks for summarizing.

  • @devetips
    @devetips 2 роки тому +1

    really the most informative explanation of SOLID principles. appreciated and thanks a lot man:)

  • @aginamabednego
    @aginamabednego Рік тому

    Kudos Philip. This explanation was easy to grasp

  • @theophilus494
    @theophilus494 3 роки тому +1

    Philip God bless you soooooooo much.... i can't thank you enough

  • @matt-g-recovers
    @matt-g-recovers 3 роки тому +2

    After watching this last night I went back and re-watched Bob's playlist on clean code... outstanding!
    Then today in a long term project interview (We interview internally for projects) I was asked, 'what are the SOLID principles of good software engineering?'
    I played it cool,
    .. 'fools, little do you know Phillipp just schooled me on this shit'
    ... barely had the words come out of my mouth when the hiring manager said "wait you know Phillipp?" ;)
    Joking aside, the synchronicity is insane man, thanks so much for everything!

  • @daniyar2718
    @daniyar2718 3 роки тому +1

    I like how you explain complex things so easy👍nice

  • @snehilsinha4689
    @snehilsinha4689 2 роки тому

    Simplest and best example with clean examples just like your clean codes @Philipp ! Awesome :)

  • @Another0neTime
    @Another0neTime 3 роки тому +2

    This guy does it again!!! Nice explanations.

  • @khanzadakashif8248
    @khanzadakashif8248 3 роки тому

    Just the thing I needed.
    Surely will start using all these principles in my future projects.... Thanks bro...

  • @alvaroisea2259
    @alvaroisea2259 3 роки тому

    Thanks for this video man!, Big fan of your channel

  • @mandroidx1474
    @mandroidx1474 3 роки тому

    This is really helpful,some tutorial only targets output without considering clean code,thanks Philipp

  • @jhngolan
    @jhngolan 3 роки тому +1

    So realy clearest explanation ever and simple practical
    Thank you Philipp

  • @montuedge
    @montuedge Рік тому

    You explain like Indians ❤ simple and easy to understand with examples.

  • @lekshmiskrishnan5652
    @lekshmiskrishnan5652 2 роки тому +1

    Thanks a lot for that awesome explanation!

  • @wilsonahanmisi1187
    @wilsonahanmisi1187 3 роки тому

    This guy is really good.... Keep it up bro

  • @Abhishek_Sawant
    @Abhishek_Sawant 3 роки тому

    Keep making such videos.👍 It truly helps a lot.😌 Thank you 🙏🙂

  • @sahilshokeen6078
    @sahilshokeen6078 3 роки тому +1

    Really amazing video

  • @haliltoprak585
    @haliltoprak585 2 роки тому

    Thank you so much for clear explanation of SOLID 🙏

  • @kareemjeiroudi1964
    @kareemjeiroudi1964 3 роки тому +16

    Well done video. Just pay attention to interface segregation. Interface segregation does not mean that clients do not need to implement the entire interface. It means that you should segregate different functions under several interfaces, and then it's up to the client to decide which interfaces to implement. I don't think the example here was demonstrative of interface segregation.

    • @PhilippLackner
      @PhilippLackner  3 роки тому +9

      agreed, thanks for the feedback!

    • @punerealestatebuilder
      @punerealestatebuilder 3 роки тому +2

      Probably onClickListener and OnLongClickListener are examples of it. Those 2 could be in a single interface, but that way you would have forced the class to implement these 2 methods even you want to use either of them.

  • @mare10rooney
    @mare10rooney 3 роки тому

    Great video Philipp, would be awesome if you would cover more of these advanced topics. Keep up the good work!

  • @abood7meed509
    @abood7meed509 2 роки тому

    Thank you it was very simple and easy to understand

  • @basitaliwrites4828
    @basitaliwrites4828 2 роки тому

    Thank you for the explanation I learned something new today

  • @NishantKumar-cr6fb
    @NishantKumar-cr6fb 3 роки тому

    Nicely and simply explained

  • @VenewebTV
    @VenewebTV 3 роки тому +1

    Amazing video, I have studied the SOLID principles and I have never understood them so easily, congratulations, greetings from Caracas, Venezuela

  • @joemoe5954
    @joemoe5954 3 роки тому

    Please make more videos like this !

  • @minasalah8210
    @minasalah8210 2 роки тому

    thanks' a lot Philipp, appreciated your efforts

  • @umairkhalid123
    @umairkhalid123 3 роки тому +4

    You got some perfect communication skills

    • @PhilippLackner
      @PhilippLackner  3 роки тому +1

      Thanks ❤️

    • @satyasaineelapala570
      @satyasaineelapala570 3 роки тому

      @@PhilippLackner Great video. I do have one doubt regarding auth in Dependency inversion. If we call auth.signInWithEmailAndPassword(), then which would be called among the functions in FirebaseAuthention and CustomApiAuthentication classes?Thanks in advance

    • @mrwhoknows
      @mrwhoknows 3 роки тому +1

      @@satyasaineelapala570 you have to pass authenticator object while creating instance of Repository, if you've passed firebaseAuthenticator then it'll use that, and vice versa

    • @satyasaineelapala570
      @satyasaineelapala570 3 роки тому

      @@mrwhoknows Thanks

  • @rizwansworld
    @rizwansworld 6 місяців тому

    Thanks man. Really helpful.

  • @susanlama
    @susanlama 3 роки тому

    This videos was so helpful. Thank you

  • @atulkumar-bb7vi
    @atulkumar-bb7vi 2 роки тому

    I liked explanation, Thanks! but Interface segregation principle is not explained properly. It states that, should have kept printLogs method in different interface and then can be implemented in classes wherever required.

  • @burakkarabekir459
    @burakkarabekir459 3 роки тому

    Great content. You made it clear for me. Thank you so much.
    .
    .
    .
    Thank you so much.

  • @Chintanparmar
    @Chintanparmar 3 роки тому +1

    If possible also make a video on Design Patterns 😅

  • @akashkumardas9670
    @akashkumardas9670 3 роки тому

    need to watch some more time. Thanks a lot

  • @OmarMohamed-ge2zg
    @OmarMohamed-ge2zg 6 місяців тому

    thank you mr philipp

  • @d-landjs
    @d-landjs 9 місяців тому

    Excellent bro !

  • @bitwise-dev
    @bitwise-dev 11 місяців тому

    Didn't realize I already did all of it long time ago.

  • @r_yan3531
    @r_yan3531 3 роки тому +1

    Hey Phillipp we need more videos on clean architecture, if possible please make a playlist on it. I will buy that playlist if it is paid but please make that playlist

  • @carguy-xv2cl
    @carguy-xv2cl 2 місяці тому

    Am I crazy or did you not instantiate any of the class member objects that you are calling methods from. Still trying to get the hang of kotlin coming from java.

  • @twominus7500
    @twominus7500 8 місяців тому

    I do not understand why we need separate authenticator interface for Firebase. We already have an abstraction for repository and we can simply create another implementation with another dependencies. Why to double abstractions there?

  • @pstlvictoras
    @pstlvictoras 3 роки тому

    do you have an example of project with clean arhitecture?

  • @atulkumar-bb7vi
    @atulkumar-bb7vi 2 роки тому

    Repo is dependent on FirebaseAuth object which is wrong, Should be asbtracted and repo should also be abstracted with separating out implementation, and separate class for logging code.

  • @rogerccaqp
    @rogerccaqp 3 роки тому

    saw videos about this topic and this helps me to understood it better.
    easy to undertand also for stating with solid and why use it
    half of the video after that i lost

  • @merryorte
    @merryorte 2 роки тому

    I think the explanation for open for extension but closed for modification was a bit confusing.
    I hope I'm understanding correctly that by modifying you mean adjusting functionality in pre-existing functions that already work fine.

  • @techmarinar
    @techmarinar 3 роки тому

    thank you very much , this is really awesome

  • @bonifaceyombwe9793
    @bonifaceyombwe9793 3 роки тому

    I always enjoy your videos. Would u do one video on adding time and date in an android studio app

    • @PhilippLackner
      @PhilippLackner  3 роки тому

      Thanks I do that in a bunch of my Playlists

  • @newbiegameplayy
    @newbiegameplayy 3 роки тому

    Please Make A Series About Clean Architecture...

  • @behnawm
    @behnawm 3 роки тому +4

    Perfection!

  • @vengateshm2122
    @vengateshm2122 3 роки тому +4

    Finally found a Bible for SOLID.❤️🙏

  • @amavrik
    @amavrik 3 роки тому

    Great explanation man! Thank you!

  • @rezarizky8470
    @rezarizky8470 3 роки тому

    Sir, u are the best!

  • @MenaSamer
    @MenaSamer 8 місяців тому

    it is good, but I need the new version of this video ... if you have a chance to do it.

  • @funnymoment9164
    @funnymoment9164 3 роки тому

    Thanks. Very good explanation.

  • @gyorgygab
    @gyorgygab 3 роки тому

    Very good video. One question regarding the Open Closed Principle: If I would create method for changing the path e.g.: open fun getPath(){...} Does this violate the principle?

  • @jayantkumar1954
    @jayantkumar1954 3 роки тому +1

    Really awesome explanation 😐😐👏

  • @vathsan3906
    @vathsan3906 3 роки тому +1

    With these vdo, I've understood what SOLID is.. Will you make a playlist making another project following MVVM, SOLID, Jetpack Compose etc... it would be nice

    • @PhilippLackner
      @PhilippLackner  3 роки тому +4

      Planned for future yes, but not a specific date yet

    • @vathsan3906
      @vathsan3906 3 роки тому

      @@PhilippLackner would love it if it comes ASAP.. maybe some app related to sports ....

  • @awais2980
    @awais2980 3 роки тому +1

    Can you please make video on Important design patterns for Android developers?
    Thanks in advance.

  • @stevebroshar3143
    @stevebroshar3143 Рік тому

    Very good presentation
    ... but off the mark on several aspects. I think you did well on S and D.
    5:10: "we don't want to affect our whole code with just one change" Cannot disagree more strongly. This is exactly what code should be written to enable. Maybe you misspoke.
    Open/closed principal does not strictly imply subclassing. It's a more general concept. It's about factoring the code so that one does not need to modify it as time progresses. Let's say I have a class that supports communications with a device that supports 10 commands. Later, the device adds support for an 11th command. I should not need to modify my existing classes to support that 11th command. The design should be such that I add a class to support the 11th command. This is a common design, right? We often see a class that supports something today and then needs updating when that thing is updated. In fact, such a class does satisfy the single-responsibility principle and it's a common design pattern. But, it's not good since it requires mods as time progresses. The OCP is about writing code one time and then never modifying it! And that is a foreign concept for most developers. We think: I can always change it in the future. But, the goal is to _not_ change it. To get the classes right and then use them like lego blocks. Not to keep re-engineering each lego block.
    The liscov breaking example does _not_ break the principle. I can use the subclass just like I use the superclass. Total missed that one. An example would be to override logError and to do something other than log an error.
    Interface segregation: it's about clients depending on things it doesn't need; not on subclasses implementing things that don't apply. Miss. Actually, your example for dependency inversion is also a good example for interface segregation.
    I think you are covering some useful coding issues, techniques and common problems. But not covering SOLID very well.

  • @RubabAzim
    @RubabAzim 2 роки тому

    Nice explanation on very complex and ambiguous topic. 👍👍 Plus i think we can do diff approach for interface segregation instead of giving default implementation.

  • @pranavyeole102
    @pranavyeole102 3 роки тому

    Well, guess I'll be here for the rest of my college, bout to dive head first into android dev.

  • @matt-g-recovers
    @matt-g-recovers 3 роки тому

    Awesome video!!

  • @puszkinowski
    @puszkinowski 3 роки тому

    great material, very helpful, thanks !

  • @binishmathew2671
    @binishmathew2671 3 роки тому

    Thanks philipp

  • @theLaughRiot00
    @theLaughRiot00 3 роки тому +8

    Hey Philipp , What about MVI pattern?Can we have any tutorial on it. Thanks

  • @hassanjamil841
    @hassanjamil841 Рік тому

    Superb!!

  • @TheCreator1197
    @TheCreator1197 3 роки тому +2

    For the open-closed principle, would you then be violating it if you provided a default parameter with the file path name, so that one could change the output location without extending the original class? Not sure if that's what you mean by closed to modification

  • @toyboatt
    @toyboatt 2 роки тому

    The Liskov example is incorrect, because the child class still implements the parent class's method and still serves as an appropriate substitute. In this example the child class fails to implement it's own method, but still successfully fulfills the parent class method.

  • @firozshaikh121
    @firozshaikh121 2 роки тому

    awesome man👍

  • @mohammedgouse5226
    @mohammedgouse5226 3 роки тому

    Iam developing an app in java ..in that navigation drawer menu items are not getting clicked and not opening sir help as soon as possible

  • @BapeRuLLZ
    @BapeRuLLZ 3 роки тому

    On the single responsibility principle example, shouldnt the error handling part be implemented in a different class? I mean it sounds and would look weird, but in principle this class still has more than one reason to change: 1. if we want to change how the user sign-in network call is implemented 2. if we want to change how the error handling works. I mean the logging part is in another class, so if we want to change only the error logging than everything is good, but if we want to change what gets called in the catch block in the first place than the class would have two reasons to change.

    • @VikashKumar-t3v8z
      @VikashKumar-t3v8z Рік тому

      Somewhere you need to catch the possible exception. I think there is no other option to handle exception like writing try-catch in the same function. If you find some solution please share that might help to understand more. Thanks

  • @oleg12395
    @oleg12395 2 роки тому

    You are the best 👌

  • @soroushlotfi6970
    @soroushlotfi6970 3 роки тому

    Brilliant content