Make Your Code Clean With the SOLID Principles

Поділитися
Вставка
  • Опубліковано 30 вер 2024
  • 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/...
    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 роки тому +171

    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.

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

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

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

      But you will understand 2x less as well

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

      @@feepin2058 not necessarily

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

      Lmao

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

      So scary 😂

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

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

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

    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 Рік тому +1

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

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

      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.

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

    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

    • @oliveryt7168
      @oliveryt7168 Рік тому +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)...

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

    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?

  • @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.

  • @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

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

    I believe you got the Liskov Substitution principle wrong.
    The principle is that you should not override the behavior of the parent class. Let's say the method of the parent class changes an attribute of the parent class which depends on it. Then when the child class overrides the method and changes the behavior so the attribute is not changed in a way the parent class expects. So this leads to bugs such as when the parent class is used in a code, it expects the behavior of the parent class and if it is substituted by the child implementation, the behavior is changed.
    In your example, when you added a new function, that's ok. It doesn't break the parent class. I don't think your example is good. There is a good example with rectangle and square. Just google it :)
    Anyways, good job explaining the rest :)

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

    Finally found a Bible for SOLID.❤️🙏

  • @sergeisalnikov6427
    @sergeisalnikov6427 2 роки тому +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))

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

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

  • @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 7 місяців тому +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.

  • @TripDude
    @TripDude Рік тому +1

    Thanks for the explanations with easy examples 👌👏

  • @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.

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

    If possible also make a video on Design Patterns 😅

  • @SandeepRajput-mq4mf
    @SandeepRajput-mq4mf 3 роки тому +2

    Please make video on things we do wrong, without even knowing it.

  • @TheCreator1197
    @TheCreator1197 2 роки тому +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

  • @blackarrowgaming915
    @blackarrowgaming915 Місяць тому

    Thakyou ❤, Please make more free contents like that, i check your "The Essentials of Industry-Level Android App Development course" but its price like my father's monthly salary in my country 🥲

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

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

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

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

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

    Really amazing video

  • @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.

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

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

  • @kulabuha
    @kulabuha 5 місяців тому

    Dear Philipp, your explanation about Interface segregation principle is not correct. This principle about that you should have several specific interfaces other then one common interface. Sorry for my criticism.

  • @atulkumar-bb7vi
    @atulkumar-bb7vi Рік тому

    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.

  • @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.

  • @atulkumar-bb7vi
    @atulkumar-bb7vi Рік тому

    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.

  • @tinykingcontractor1396
    @tinykingcontractor1396 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:)

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

    I like how you explain complex things so easy👍nice

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

    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.

  • @twominus7500
    @twominus7500 3 місяці тому

    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?

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

    This guy does it again!!! Nice explanations.

  • @yoyomario
    @yoyomario 5 місяців тому

    I'm more disturbed with the way you put your brackets, but that's just me :)

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

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

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

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

  • @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

  • @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

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

    thanks' a lot Philipp, appreciated your efforts

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

    as a programmer that has never seen any Kotlin code, "suspend fun" made me cackle

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

    Perfection!

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

    Its good to see the stuff I usually do put into a list.. notice I said USUALLY hehe

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

    Please Make A Series About Clean Architecture...

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

    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

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

    do you have an example of project with clean arhitecture?

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

    1:36 A module should be responsible to one, and only one, actor. © Uncle Bob

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

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

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

    The "Inject" part is as hard to understand as usual.....

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

    So if u want to write two lines of code u need to write 50 lines of code good lesson philip 😄

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

    Thanks a lot for that awesome explanation!

  • @MenaSamer
    @MenaSamer 3 місяці тому

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

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

    Thank you it was very simple and easy to understand

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

    Yes, Clear as Mud = Will have to re-watch :)

  • @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

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

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

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

    Video title should rename it to:
    What other Tutorial dont tell you!

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

    Best video about SOLID I've ever seen

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

    is there somewhere that you put this code? thanks!

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

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

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

    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?

  • @saul5x
    @saul5x 3 місяці тому

    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!

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

    chatgpt:
    The Open/Closed Principle (OCP) suggests that you should design your software in a way that allows for new functionality to be added through extension, rather than modification of existing code.
    This is particularly important for mature and stable codebases, as modifying existing code can be risky and can introduce new bugs or unexpected behavior. By using inheritance, composition, or polymorphism to add new functionality, you can reduce the risk of introducing new bugs or breaking existing code.
    //It does not make sense not to modifing a new code while developing new feature

  • @Georgggg
    @Georgggg Місяць тому

    Drop this and use Kotlin, instead

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

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

  • @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 ....

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

    So realy clearest explanation ever and simple practical
    Thank you Philipp

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

    Someone actually disliked this gem of a video...??! Outrageous...

  • @rizwansworld
    @rizwansworld 2 місяці тому

    Thanks man. Really helpful.

  • @cesarlabastida1392
    @cesarlabastida1392 10 місяців тому

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

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

    need to watch some more time. Thanks a lot

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

    Most of the examples here come down to requirements not principles. For example 13:30. If there is no requirement to support different auth implementations then don't implement it. It adds noise to the code and violates KISS principles.
    Even the crazy file logging example from the start shouldn't be changed if there is no need to support different output filenames (of course there is a need and burring the filename inside a function is pretty bad) but that's a requirement not a principle

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

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

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

    Thank you so much for clear explanation of SOLID 🙏

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

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

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

    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.

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

    Thank you for the explanation I learned something new today

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

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

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

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

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

    thank you mr philipp

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

    Wao..👍👍👍👍👍

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

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

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

    Hi Philipp.... Could you please do a video on How to use Ktor on an Android client...

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

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

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

    👍

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

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

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

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

    super simple the best :D

  • @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

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

    grateful :)

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

    Great explanation

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

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

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

    I love you philip 🥰

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

    We need more of this
    Can you Mix this with an app tutorial
    With mvvm , injection

  • @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.

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

    Kudos Philip. This explanation was easy to grasp

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

    You are the best 👌

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

    Thanks Philipp

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

    please have video on websocket.......................

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

      I have a full course on it. Check pl-coding.com/premium-courses

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

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

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

    Excellent bro !