Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. All high-level classes must depend only on Interfaces

All high-level classes must depend only on Interfaces

Scheduled Pinned Locked Moved The Lounge
comdesigngame-devbeta-testingtutorial
69 Posts 15 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Ravi Bhavnani

    IMHO, a member friendship violates Liskov.

    hpcoder2 wrote:

    The only time mocking is really needed is when it is impractical to instantiate the dependency in the CI environment. Examples might include a full database, or something that depends on network resources.

    And that's often the case when testing enterprise systems that include several cooperating independent subsystems.  That's the case at my shop. /ravi

    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

    H Offline
    H Offline
    hpcoder2
    wrote on last edited by
    #60

    I have no problem with the independent subsystems being mocked. There are relatively few of these. In examples I've seen, every single class implements an interface, and every interacting class is mocked, leading to triple the number of classes, and a nightmare to read and/or debug the code. Way too much! Re friendship violating Liskov, then so much the worse for Liskov. Friendship has its place and uses, but shouldn't be overused - just like global variables, mutable members and dependency injection.

    R 1 Reply Last reply
    0
    • H hpcoder2

      I have no problem with the independent subsystems being mocked. There are relatively few of these. In examples I've seen, every single class implements an interface, and every interacting class is mocked, leading to triple the number of classes, and a nightmare to read and/or debug the code. Way too much! Re friendship violating Liskov, then so much the worse for Liskov. Friendship has its place and uses, but shouldn't be overused - just like global variables, mutable members and dependency injection.

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #61

      hpcoder2 wrote:

      I have no problem with the independent subsystems being mocked. There are relatively few of these.

      Right.  In our codebase, services tend to have at most about 3-4 dependencies (independent services).

      hpcoder2 wrote:

      In examples I've seen, every single class implements an interface

      Ouch.  I agree that's overkill. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • R Ravi Bhavnani

        jschell wrote:

        You are claiming that it is successful. Not that it could be but rather that it is. So how did you measure that?

        By measuring our sprint velocity and bug counts. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #62

        Ravi Bhavnani wrote:

        and bug counts.

        You originally responded (quoted) to the following "All high-level classes must depend only on Interfaces" Are you claiming that interfaces and nothing else reduced bug counts? Versus and not the same as a large number of other code and process (not just coding) methods. And the sum total of those reduced bug counts? And what was your time period and measurement. So for example you started with no processes in place in Jan of 2021, and you measured your production bug rate then for the last year (to Jan of 2020.) Then you implemented the new processes and now your production bug rate is 50% less? Or 90% less? Specifically what are those numbers? (Might note that I spend 15 years doing significant/principle work in Process Control procedures so I am fact rather knowledgeable both in the theory and the practice and the reality of doing this.)

        R 1 Reply Last reply
        0
        • J jschell

          Ravi Bhavnani wrote:

          and bug counts.

          You originally responded (quoted) to the following "All high-level classes must depend only on Interfaces" Are you claiming that interfaces and nothing else reduced bug counts? Versus and not the same as a large number of other code and process (not just coding) methods. And the sum total of those reduced bug counts? And what was your time period and measurement. So for example you started with no processes in place in Jan of 2021, and you measured your production bug rate then for the last year (to Jan of 2020.) Then you implemented the new processes and now your production bug rate is 50% less? Or 90% less? Specifically what are those numbers? (Might note that I spend 15 years doing significant/principle work in Process Control procedures so I am fact rather knowledgeable both in the theory and the practice and the reality of doing this.)

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #63

          jschell wrote:

          Are you claiming that interfaces and nothing else reduced bug counts?

          Obviously not.

          jschell wrote:

          I am fact rather knowledgeable both in the theory and the practice and the reality of doing this.)

          Yes, we're all very impressed by your intellect. /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          J 1 Reply Last reply
          0
          • R Ravi Bhavnani

            jschell wrote:

            Are you claiming that interfaces and nothing else reduced bug counts?

            Obviously not.

            jschell wrote:

            I am fact rather knowledgeable both in the theory and the practice and the reality of doing this.)

            Yes, we're all very impressed by your intellect. /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #64

            Ravi Bhavnani wrote:

            Yes, we're all very impressed by your intellect.

            And yet I do know what I am talking about. While you keep responding but fail to answer the original question - how did you specifically measure the improvement? - What was your specific improvement.? I know that the answers to both those questions are available if in fact you are following stringent Process Control processes. And those processes would demonstrate that your original claim is in fact correct. Versus, as I said, applying it with the expectation of an improvement without any backing for that. That supposition would not be unique to you of course. I have seen many people make the claim. But who were unaware of that vast body of work that does in fact show that improvements (objective measured) are possible. But only if one does the actual work, including the Process Control processes.

            R 1 Reply Last reply
            0
            • J jschell

              Ravi Bhavnani wrote:

              Yes, we're all very impressed by your intellect.

              And yet I do know what I am talking about. While you keep responding but fail to answer the original question - how did you specifically measure the improvement? - What was your specific improvement.? I know that the answers to both those questions are available if in fact you are following stringent Process Control processes. And those processes would demonstrate that your original claim is in fact correct. Versus, as I said, applying it with the expectation of an improvement without any backing for that. That supposition would not be unique to you of course. I have seen many people make the claim. But who were unaware of that vast body of work that does in fact show that improvements (objective measured) are possible. But only if one does the actual work, including the Process Control processes.

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #65

              jschell wrote:

              While you keep responding but fail to answer the original question - how did you specifically measure the improvement? - What was your specific improvement.?

              Actually I did answer your questions.  Perhaps you missed reading my reply of 27-Feb-2024 10.46.  Here it is again:

              Ravi Bhavnani wrote:

              By measuring our sprint velocity and bug counts.

              The increase in sprint velocity showed we were able to release new and modified functionality consistently faster (without growing our team), and the reduction in issues per new feature/enhancement spoke to better code quality brought about by the increase in the number of unit tests.  Defining our injected dependencies as interfaces (vs. concrete classes) makes it easier to write unit tests because it's trivial to mock them.  This is especially true when many of our service dependencies are implemented by other teams. /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              J 1 Reply Last reply
              0
              • R Ravi Bhavnani

                jschell wrote:

                While you keep responding but fail to answer the original question - how did you specifically measure the improvement? - What was your specific improvement.?

                Actually I did answer your questions.  Perhaps you missed reading my reply of 27-Feb-2024 10.46.  Here it is again:

                Ravi Bhavnani wrote:

                By measuring our sprint velocity and bug counts.

                The increase in sprint velocity showed we were able to release new and modified functionality consistently faster (without growing our team), and the reduction in issues per new feature/enhancement spoke to better code quality brought about by the increase in the number of unit tests.  Defining our injected dependencies as interfaces (vs. concrete classes) makes it easier to write unit tests because it's trivial to mock them.  This is especially true when many of our service dependencies are implemented by other teams. /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #66

                First of course those are not numbers. Second I responded to you and said the following... "Are you claiming that interfaces and nothing else reduced bug counts?"

                Ravi Bhavnani wrote:

                The increase in sprint velocity showed we were able to release new and modified functionality

                Yes one can modify coding practices and development processes to achieve various measurable benefits. But you cannot due that solely by using interfaces. Please read the Original Post. It says nothing about a comprehensive rework of coding practices and development processes. It says that nothing but requiring interfaces is being required.

                R 1 Reply Last reply
                0
                • J jschell

                  First of course those are not numbers. Second I responded to you and said the following... "Are you claiming that interfaces and nothing else reduced bug counts?"

                  Ravi Bhavnani wrote:

                  The increase in sprint velocity showed we were able to release new and modified functionality

                  Yes one can modify coding practices and development processes to achieve various measurable benefits. But you cannot due that solely by using interfaces. Please read the Original Post. It says nothing about a comprehensive rework of coding practices and development processes. It says that nothing but requiring interfaces is being required.

                  R Offline
                  R Offline
                  Ravi Bhavnani
                  wrote on last edited by
                  #67

                  jschell wrote:

                  First of course those are not numbers.

                  Do you mean sprint velocity, code coverage and bug counts aren't numbers?

                  jschell wrote:

                  But you cannot due that solely by using interfaces.

                  Correct.  And I didn't imply you could.  Read my comment of 17-Feb-24 13:11 again. /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  J 1 Reply Last reply
                  0
                  • R Ravi Bhavnani

                    jschell wrote:

                    First of course those are not numbers.

                    Do you mean sprint velocity, code coverage and bug counts aren't numbers?

                    jschell wrote:

                    But you cannot due that solely by using interfaces.

                    Correct.  And I didn't imply you could.  Read my comment of 17-Feb-24 13:11 again. /ravi

                    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #68

                    Ravi Bhavnani wrote:

                    Do you mean sprint velocity, code coverage and bug counts aren't numbers?

                    No. Those are measurable quantities which over time can reflect a change. A number is 3. You could state that you improved 30%. Or that your average bug count went from 30 to 3. Those are numbers.

                    Ravi Bhavnani wrote:

                    Correct.  And I didn't imply you could.  Read my comment of 17-Feb-24 13:11 again.

                    Stating it again.... The OP said that the ONLY thing requested was adding interfaces. Nothing else. You responded directly to that, you quoted that line from the OP. And stated you "follow that guideline at my shop." You did not qualify that by suggesting that it was part of a larger process that would lead to better code. Perhaps you meant to encompass the entire development process but that is NOT what you said in your original post.

                    1 Reply Last reply
                    0
                    • R raddevus

                      I'm very interested in feedback on this. Yes, it's somewhat related to my latest article[^], but I'm going through what I explain below, right now.. What if you were going to design some new service or app and you were told:

                      Development Manger:

                      "All high-level classes must depend only on Interfaces."

                      What if I told you that and was entirely serious. Would you balk? or think, "Yes, that is the way it is and should be." After that your manager says,

                      Development Manager:

                      "Something else will decide how to build the implementation which will fulfill the Interfaces."

                      Would that sound normal to you, or completely crazy? Or somewhere in between? The Implications Do you honestly understand the implications? No Implementation Code One of the implications is that the code Service or App you are creating basically has no implementation code in it. (Or very little.) Why? Because your high-level app only depends on easily-replaceable Interfaces. That means if you want to see the implementation, you'll need to go to the Library (probably a separate project) which contains the implementation that is used to fulfill the Interface. How do you feel about that? Do you know how crazy it is to look at project that has been designed this way? Have you ever experience a project that is carried out like this? Why I'm Thinking About This Even More? I have just completed 50 pages (of a total of 241) of the very old book (2013) DependencyInjection With Unity (free PDF or EPUB at link)[^].

                      M Offline
                      M Offline
                      Member_5893260
                      wrote on last edited by
                      #69

                      Hmmm... once you decide that *all* something must do *something*, before you even know what problem you're about to solve, you've decided that reality takes second place to what you've decided reality should be. "Dijkstra would not like this" <- his immortality, for those who get the reference.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups