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. General Programming
  3. Design and Architecture
  4. 'Interface' Considered Harmful : Uncle Bob

'Interface' Considered Harmful : Uncle Bob

Scheduled Pinned Locked Moved Design and Architecture
questioncomregexoopdiscussion
18 Posts 7 Posters 0 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.
  • P Pete OHanlon

    I gather that this article needed the help of a proctologist with a torch.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    Pete O'Hanlon wrote:

    with a torch

    Or maybe just an ear-trumpet? X|

    1 Reply Last reply
    0
    • P Pete OHanlon

      I gather that this article needed the help of a proctologist with a torch.

      P Offline
      P Offline
      popchecker
      wrote on last edited by
      #6

      Was that a brainless question? :(

      L 1 Reply Last reply
      0
      • P popchecker

        Was that a brainless question? :(

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7

        Not completely, but it's more a Lounge type discussion, than a technical question.

        P 1 Reply Last reply
        0
        • L Lost User

          Not completely, but it's more a Lounge type discussion, than a technical question.

          P Offline
          P Offline
          popchecker
          wrote on last edited by
          #8

          Oh that explains the hatred towards my question. But I was not trying to degrade that article. All I meant about the technical aspects of that idea. Sorry for my ignorance; I thought my solution can overcome the problem specified in the article. Thanks, Pop

          L P 2 Replies Last reply
          0
          • P popchecker

            Oh that explains the hatred towards my question. But I was not trying to degrade that article. All I meant about the technical aspects of that idea. Sorry for my ignorance; I thought my solution can overcome the problem specified in the article. Thanks, Pop

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #9

            I think the "hatred" was directed at Uncle Bob, not at you.

            P 1 Reply Last reply
            0
            • L Lost User

              I think the "hatred" was directed at Uncle Bob, not at you.

              P Offline
              P Offline
              popchecker
              wrote on last edited by
              #10

              Thank you! :)

              1 Reply Last reply
              0
              • P popchecker

                Oh that explains the hatred towards my question. But I was not trying to degrade that article. All I meant about the technical aspects of that idea. Sorry for my ignorance; I thought my solution can overcome the problem specified in the article. Thanks, Pop

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #11

                Was there hatred towards your article? I was actually commenting that o' Uncle Bob seemed to have pulled his argument out of his posterior.

                P 1 Reply Last reply
                0
                • P Pete OHanlon

                  Was there hatred towards your article? I was actually commenting that o' Uncle Bob seemed to have pulled his argument out of his posterior.

                  P Offline
                  P Offline
                  popchecker
                  wrote on last edited by
                  #12

                  Sorry I was perplexed

                  1 Reply Last reply
                  0
                  • P popchecker

                    Hi, In his recent blog[^] Uncle Bob come up with a situation that explains interface is harmful. Here is the code snippet taken from his blog.

                    public class Subject {
                    private List<Observer> observers = new ArrayList<>();
                    private void register(Observer o) {
                    observers.add(o);
                    }
                    private void notify() {
                    for (Observer o : observers)
                    o.update();
                    }
                    }

                    public class MyWidget {...}

                    public class MyObservableWidget extends MyWidget, Subject {
                    ...
                    }

                    Here he explains that to implement Observer pattern done correctly, compilers must allow multiple inheritance. So my question is why don't the MyObservableWidget implement using dependency injection like below to avoid multiple inheritance with greater degree of separation of concerns?

                    public class MyObservableWidget extends MyWidget {

                    private Subject subject;

                    public MyObservableWidget(Subject subject) {
                    this.subject = subject;
                    }

                    }

                    Of course the Subject class should be an abstract class. Please let me know your thoughts. Thanks, Pop

                    K Offline
                    K Offline
                    Keld Olykke
                    wrote on last edited by
                    #13

                    Hi, Thank you for the blog link. You propose what is called mixin, which is really the go to solution to avoid bloated inheritance hierarchies. The good thing about mixin of Subject is that you hide functionality and avoids to duplicate the code in Subject. The bad thing is that you still need to duplicate the code that calls Subject aka relaying. DI with mixin is also good since you make the dependency known to the outside. This opens up for implementation replacement from the outside and gives better transparency. However, Uncle Bob really wants to hide stuff and use inheritance to avoid ANY code duplication and he can't do that in a single inheritance language. I love interfaces because they form a specification layer without any implementation details. I love abstract classes because they can be implementation templates for concrete classes. I do not want to mix the 2 concerns - at all. And it IS a tad annoying when you need add mixin in you abstract classes to avoid code duplication. I wouldn't mind multiple inheritance, if the language/compiler could manage diamonds in a consistent and obvious way (No, C++ doesn't). The class hierarchy is however implementation - not specification (IMHO). Uncle Bob doesn't address that view on the interface keyword.... and I am not sure the interface keyword had that view in mind when invented.

                    T 1 Reply Last reply
                    0
                    • K Keld Olykke

                      Hi, Thank you for the blog link. You propose what is called mixin, which is really the go to solution to avoid bloated inheritance hierarchies. The good thing about mixin of Subject is that you hide functionality and avoids to duplicate the code in Subject. The bad thing is that you still need to duplicate the code that calls Subject aka relaying. DI with mixin is also good since you make the dependency known to the outside. This opens up for implementation replacement from the outside and gives better transparency. However, Uncle Bob really wants to hide stuff and use inheritance to avoid ANY code duplication and he can't do that in a single inheritance language. I love interfaces because they form a specification layer without any implementation details. I love abstract classes because they can be implementation templates for concrete classes. I do not want to mix the 2 concerns - at all. And it IS a tad annoying when you need add mixin in you abstract classes to avoid code duplication. I wouldn't mind multiple inheritance, if the language/compiler could manage diamonds in a consistent and obvious way (No, C++ doesn't). The class hierarchy is however implementation - not specification (IMHO). Uncle Bob doesn't address that view on the interface keyword.... and I am not sure the interface keyword had that view in mind when invented.

                      T Offline
                      T Offline
                      TheGreatAndPowerfulOz
                      wrote on last edited by
                      #14

                      Keld ร˜lykke wrote:

                      No, C++ doesn't

                      I think it does. Why do you say it doesn't?

                      Keld ร˜lykke wrote:

                      class hierarchy is however implementation - not specification

                      Agreed. Hence, I don't think interfaces are "harmful", but what Uncle Bob was really complaining about is not being able to have multiple base classes. However, I think true separation of concerns would use neither DI nor inheritance to do his observer pattern but rather a separate "observer manager" class that does both the observing and registration/deregistration.

                      #SupportHeForShe

                      If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun Only 2 things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein

                      K 1 Reply Last reply
                      0
                      • T TheGreatAndPowerfulOz

                        Keld ร˜lykke wrote:

                        No, C++ doesn't

                        I think it does. Why do you say it doesn't?

                        Keld ร˜lykke wrote:

                        class hierarchy is however implementation - not specification

                        Agreed. Hence, I don't think interfaces are "harmful", but what Uncle Bob was really complaining about is not being able to have multiple base classes. However, I think true separation of concerns would use neither DI nor inheritance to do his observer pattern but rather a separate "observer manager" class that does both the observing and registration/deregistration.

                        #SupportHeForShe

                        If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun Only 2 things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein

                        K Offline
                        K Offline
                        Keld Olykke
                        wrote on last edited by
                        #15

                        Well, by not consistent I mean that you can end up with compiler accepted code, but it is unknown what it will do. The "dreaded diamond" refers to the situation where class C inherits from 2 classes B1 & B2 that both inherits the same base A. C will have 2 copies of all fields from A and at runtime it is undefined which copy you address.

                        T 1 Reply Last reply
                        0
                        • K Keld Olykke

                          Well, by not consistent I mean that you can end up with compiler accepted code, but it is unknown what it will do. The "dreaded diamond" refers to the situation where class C inherits from 2 classes B1 & B2 that both inherits the same base A. C will have 2 copies of all fields from A and at runtime it is undefined which copy you address.

                          T Offline
                          T Offline
                          TheGreatAndPowerfulOz
                          wrote on last edited by
                          #16

                          Ah, sure, I see. But you can solve that by using "virtual" inheritance. Then there's only one instance of A. Of course, you can't always do that when using third-party libraries.

                          #SupportHeForShe

                          If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun Only 2 things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein

                          K 1 Reply Last reply
                          0
                          • T TheGreatAndPowerfulOz

                            Ah, sure, I see. But you can solve that by using "virtual" inheritance. Then there's only one instance of A. Of course, you can't always do that when using third-party libraries.

                            #SupportHeForShe

                            If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun Only 2 things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein

                            K Offline
                            K Offline
                            Keld Olykke
                            wrote on last edited by
                            #17

                            Yes. If C++ was a game I would call it a tad unforgiving :-)

                            1 Reply Last reply
                            0
                            • P popchecker

                              Hi, In his recent blog[^] Uncle Bob come up with a situation that explains interface is harmful. Here is the code snippet taken from his blog.

                              public class Subject {
                              private List<Observer> observers = new ArrayList<>();
                              private void register(Observer o) {
                              observers.add(o);
                              }
                              private void notify() {
                              for (Observer o : observers)
                              o.update();
                              }
                              }

                              public class MyWidget {...}

                              public class MyObservableWidget extends MyWidget, Subject {
                              ...
                              }

                              Here he explains that to implement Observer pattern done correctly, compilers must allow multiple inheritance. So my question is why don't the MyObservableWidget implement using dependency injection like below to avoid multiple inheritance with greater degree of separation of concerns?

                              public class MyObservableWidget extends MyWidget {

                              private Subject subject;

                              public MyObservableWidget(Subject subject) {
                              this.subject = subject;
                              }

                              }

                              Of course the Subject class should be an abstract class. Please let me know your thoughts. Thanks, Pop

                              ๊ฐ• Offline
                              ๊ฐ• Offline
                              ๊ฐ•๋‚จํ’€์‹ธ๋กฑ์‹ ์„ธ๊ฒฝ์‹ค์žฅ
                              wrote on last edited by
                              #18

                              #๊ฐ•๋‚จํ’€์‹ธ๋กฑ์‹ ์„ธ๊ฒฝ,#๊ฐ•๋‚จํ’€์Œ€๋กฑ,#๊ฐ•๋‚จํ’€์‹ธ๋กฑ

                              ๋‹ค๊ฐ€๋ฏธ๋Ÿฌ๋ฅผ๋ณด์‹œ๋ฉด๋ฉ๋‹ˆ๋‹ค.๊ฐ์ข…์ด๋ฒคํŠธ,์ƒ์ผํŒŒํ‹ฐ,์ง„๊ธ‰์‹๋“ฑ๊ธฐ๋ถ„์ข‹์€๋‚ ์ƒ์ผ€์ต&์ดˆ์ฝ”์ผ€์ต์„์„œ๋น„์Šค๋กœ์ œ๊ณต!๋ชจ์ž„์—๋Š”์—ญ์‹œ๊ฐ•๋‚จ์ตœ๊ณ ์˜์„œ๋น„์Šค๋กœ์ดˆ๋Œ€ํ•ฉ๋‹ˆ๋‹ค.๊ฐ•๋‚จํ’€์‹ธ๋กฑ(Ha
                              rdFull)์‹ ์„ธ๊ฒฝ์‹ค์žฅ์€๊ณผ๋Œ€๊ด‘๊ณ ๋ฅผํ•˜์ง€์•Š์Šต๋‹ˆ๋‹ค.๊ฐ•๋‚จ์–ด๋””๋ฅผ๊ฐ€์…”๋„๋ฃธ์•ˆ์—์„œ๋ถ€๋„๋Ÿฝ๊ฒŒ๋†€์ง€์•Š์Šต๋‹ˆ๋‹ค.๊ทธ๋งŒํผ์ˆ˜์งˆ๊ณผ๋งˆ๋“œ๊ฐ€๋ณด์žฅ๋˜์–ด์žˆ์œผ๋‹ˆ1%์˜๊ฑฑ์ •๋„ํ•˜
                              ์ง€๋งˆ์‹œ๊ณ ,์ฆ๊ฑฐ์šด๋งˆ์Œ์œผ๋กœ๋ฐฉ๋ฌธํ•ด์ฃผ์„ธ์š”!๊ฐ•๋ ฅํ•œ์–ธ๋‹ˆ๋“ค์˜์ ๊ทน๋Ÿฌ์‰ฌ&์• ์ธ๋ชจ๋“œ๋กœํ™”๋ˆํ•œ์ˆ ์ž๋ฆฌ๊ฐ€ํ•ญ์ƒ์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.๊ณ ๊ฐ๋งŒ์กฑ1์œ„์˜๊ฐ•๋‚จํ’€์‹ธ๋กฑ
                              &์„ ๋ฆ‰๋ฌผ๊ณ ๊ธฐ์˜€์Šต๋‹ˆ๋‹ค.๊ฐ•๋‚จํ’€์‹ธ๋กฑ๋งค์ง๋ฏธ๋Ÿฌ์˜๋ฌผ๊ณ ๊ธฐ๋Š”์•„๋ฌด๋‚˜์™€์„œ์ผํ• ์ˆ˜์žˆ๋Š”"ํ’€์‹ธ๋กฑ
                              "์ด์•„๋‹™๋‹ˆ๋‹ค.์–ธ๋‹ˆ๋“ค์€๋ชจ๋‘๋ฉด์ ‘์„ํ†ตํ•˜์—ฌ์‚ฌ์ด์ฆˆ์ข‹์€์–ธ๋‹ˆ๋“ค๋งŒ์—„์„ ํ•˜๊ณ ์žˆ์œผ๋ฉฐ,์ฃผ1ํšŒ์–ธ๋‹ˆ๋“ค์ขŒ๋‹ดํšŒ๋ฅผํ†ตํ•˜์—ฌ๋งˆ์ธ๋“œ๊ต์œก์„์‹ค์‹œํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.๋˜ํ•œ์“ฐ๋ฆฌ์•„์›ƒ์ œ๋ฅผ๋„์ž…ํ•˜์—ฌ,์†๋‹˜๋ฐฉ์—์„œ
                              ์กฐ๊ธˆ์˜์‹ค์ˆ˜๋ผ๋„3๋ฒˆ์ด์ƒ์†๋‹˜๋“ค๊ป˜ํด๋ ˆ์ž„์ด๋“ค์–ด์˜ค๋ฉด,๊ทธ์–ธ๋‹ˆ๋Š”๋”์ด์ƒ๊ฐ€๊ฒŒ์—์ถœ๊ทผํ• ์ˆ˜์—†๋Š”์‹œ์Šคํ…œ์ž…๋‹ˆ๋‹ค^^๋”ฐ๋ผ์„œ,๋‹ค๋ฅธ๊ณณ๊ณผ๋Š”๋‹ฌ๋ฆฌ๋ณด๋‹ค์ข‹์€์ˆ˜์งˆ!๋ณด๋‹ค๊ธฐ
                              ๋˜ฅ์ฐฌ๋งˆ์ธ๋“œ๋ฅผ๊ฐ€์ง„์–ธ๋‹ˆ๋“ค๊ณผํ™”๋ˆํ•˜๊ฒŒ๋‹ฌ๋ฆฌ์‹ค์ˆ˜์žˆ์œผ๋ฉฐ,์˜ค์…”์„œ์ดˆ์ด์Šคํ•œ๋ฒˆ๋ณด์‹œ๋ฉด์ œ๋ง์ด๊ฑฐ์ง“์ด์•„๋‹ˆ๋ผ๋Š”๊ฒƒ์„์•„์‹ค์ˆ˜์žˆ์œผ์‹ค๊ฒ๋‹ˆ๋‹ค^^โ– ๊ฐ•๋‚จํ’€์‹ธ๋กฑ์„œ๋น„์Šค
                              ์‹œ๊ฐ„-์ด2์‹œ๊ฐ„ํƒ€์ž„(์–‘์ฃผ+๋งฅ์ฃผ+๊ณ ๊ธ‰์•ˆ์ฃผset๋ฌด์ œํ•œ)-1์‹œ๊ฐ„10๋ถ„(๋ž€์ œ๋ฆฌ๋ฆฝ์„œ๋น„์Šค2๋ฒˆ)-45๋ถ„(์•ผ๊ตฌ์žฅ์—์„œ์ฆ๊ฑฐ์šด์‹œ๊ฐ„)โ– ๊ฐ•๋‚จํ’€์‹ธ๋กฑ๊ฐ€๊ฒฉ-8์‹œ์ด์ „1
                              ์ธ28๋งŒ/2์ธ์ด์ƒ30๋งŒ-8์‹œ์ดํ›„1์ธ35๋งŒ/2์ธ์ด์ƒ32๋งŒ(๊ธฐํƒ€์ถ”๊ฐ€๋น„์šฉ์€์ ˆ๋Œ€์—†์Šต๋‹ˆ๋‹ค.)๊ฐ•๋‚จํ’€์‹ธ๋กฑ๋ฌผ๊ณ ๊ธฐโ—€์‚ผ์„ฑ์„ ๋ฆ‰ํญ์Šค&๊ฐ•๋‚จ์ปคํ”ผ๋นˆ๋ช…
                              ์†Œ์•ˆ๋‚ด๊ฐ•๋‚จํ’€์‹ธ๋กฑ๋ฌผ๊ณ ๊ธฐโ—€๊ฐ•๋‚จ๋งˆ์นด์˜ค์˜์ƒˆ์ด๋ฆ„"์„ ๋ฆ‰๋ฌผ๊ณ ๊ธฐ"์‹ ์„ธ๊ฒฝํŒ€์žฅ๊ฒฝ์šด๊ธฐ์ถค์„์œ ํ–‰์‹œํ‚จ๋ถ€์‚ฐ์—ฌ๋Œ€ํ•™์ƒ๋ถ„!!์—ญ์‹œ์ข‹๋„คโ™ฅ๋‹ค์‹œ๋ด๋„์˜ˆ์˜๋‹ค..
                              ๋„๋ฆฌํผ๋œจ๋ ค์ฃผ์„ธ์š”์ œ๊ฐ€์—ฐ๋ฝ์ด๋‹ฟ์„์ˆ˜์žˆ๊ฒŒใ…‹ใ…‹ใ…‹โ€ช#โ€Ž์นœ์ถ”โ€ฌ๋‹ค๋ฐ›์•„์š”โ€ช#โ€Ž๊ฐ•๋‚จํ’€์‹ธ๋กฑโ€ฌโ€ช#โ€Žfollowโ€ฌ[No.1]ํ”„๋ฆฌ๋ฏธ์—„๋น„์ง€๋‹ˆ์Šค์„ผ
                              ํ„ฐMo

                              ,

                              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