Skip to main content
added 377 characters in body
Source Link
Lucas
  • 298
  • 1
  • 4

Why multiple inheritance is not more popular? Take the example:

  class X 
  {
      public void doSomething() { ... }
  }
  class Y
  {
      public void doSomething() { ... }
  }
  class Z extends X, Y
  {
  }

What should method doSomething of class Z do? In multiple inheritance many such conflicts do exist. On single inheritance you would be forced to use delegation. Which is annoying but more controlled.

In that examples you can define it is the doSomething of the first extended class. However if you imagine X has no doSomething, you develop your extension believing the Y.doSomethibg will be called and the author of X class latter added the doSomething, then a modification on the base library will introduce a inconsistency on your code that the compiler will not recognize.

I am not defending the status quo. I think languages need to evolve and incorporate patterns and other kinds of polimorphimsm... For example, most of time the builder pattern is a ugly hack for the lack of named parameters. I I use it on Java, but not in JavaScript. But modify that takes time and a lot of research.

Why multiple inheritance is not more popular? Take the example:

  class X 
  {
      public void doSomething() { ... }
  }
  class Y
  {
      public void doSomething() { ... }
  }
  class Z extends X, Y
  {
  }

What should method doSomething of class Z do? In multiple inheritance many such conflicts do exist. On single inheritance you would be forced to use delegation. Which is annoying but more controlled.

I am not defending the status quo. I think languages need to evolve and incorporate patterns and other kinds of polimorphimsm... For example, most of time the builder pattern is a ugly hack for the lack of named parameters. I I use it on Java, but not in JavaScript. But modify that takes time and a lot of research.

Why multiple inheritance is not more popular? Take the example:

  class X 
  {
      public void doSomething() { ... }
  }
  class Y
  {
      public void doSomething() { ... }
  }
  class Z extends X, Y
  {
  }

What should method doSomething of class Z do? In multiple inheritance many such conflicts do exist. On single inheritance you would be forced to use delegation. Which is annoying but more controlled.

In that examples you can define it is the doSomething of the first extended class. However if you imagine X has no doSomething, you develop your extension believing the Y.doSomethibg will be called and the author of X class latter added the doSomething, then a modification on the base library will introduce a inconsistency on your code that the compiler will not recognize.

I am not defending the status quo. I think languages need to evolve and incorporate patterns and other kinds of polimorphimsm... For example, most of time the builder pattern is a ugly hack for the lack of named parameters. I I use it on Java, but not in JavaScript. But modify that takes time and a lot of research.

Source Link
Lucas
  • 298
  • 1
  • 4

Why multiple inheritance is not more popular? Take the example:

  class X 
  {
      public void doSomething() { ... }
  }
  class Y
  {
      public void doSomething() { ... }
  }
  class Z extends X, Y
  {
  }

What should method doSomething of class Z do? In multiple inheritance many such conflicts do exist. On single inheritance you would be forced to use delegation. Which is annoying but more controlled.

I am not defending the status quo. I think languages need to evolve and incorporate patterns and other kinds of polimorphimsm... For example, most of time the builder pattern is a ugly hack for the lack of named parameters. I I use it on Java, but not in JavaScript. But modify that takes time and a lot of research.