What is the primary competing design pattern for specific inheritance in application architecture?

Sometimes I come across comments about inheritance that are “out of style” in the corporate application architecture, but I did not find a link to an article describing a competing theory. Also, is there a difference in implementation if the application is already built as opposed to starting from scratch? I believe that this may be due to a greater load on the interfaces, but I'm not sure.

+3
source share
7 answers

I think you are referring to the Design Principle:

"Approve composition over Inheritance."

+7
source

( ) .

,

 public class B extends A implements I {
    // now I have all the methods from A
 }

public class B implements I {
     private I a;

     // delegate all methods
     public void methodOne(){
          a.methodOne();
     }
}

, :

  • ( , , Java)
  • ( , , , ).
  • ( ). .
+3

, - , , :

Phillips , Flatheads.

, , , , .

- "is-a" vs. "has-a" - , ( ), . , .

, . : " , ", " - ", ? ?

- . , - , ; -)

[ !]

+2

, . : .

: , , , , , . - , , .

0

Smalltalk Perl. . .

0

, . 2003 , - . , 2009 !

0

++, mixins ( : , mixins):

Wikipedia: http://en.wikipedia.org/wiki/Mixin
Dr. Dobbs: http://www.ddj.com/cpp/184404445.

" " (CRTP):

Wikipedia: http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern.

CRTP mixins, .

"" ( ), , mixins . , , , .

, CRTP , ( ) , . , .

... , ++, . mixin .

mixins , . , , . , " " , , "", .

0

Source: https://habr.com/ru/post/1711536/


All Articles