Why do most system architects insist on first programming to an interface?

后端 未结 16 2284
离开以前
离开以前 2020-12-05 00:32

Almost every Java book I read talks about using the interface as a way to share state and behaviour between objects that when first \"constructed\" did not seem to share a r

16条回答
  •  温柔的废话
    2020-12-05 01:25

    You could see this from a perl/python/ruby perspective :

    • when you pass an object as a parameter to a method you don't pass it's type , you just know that it must respond to some methods

    I think considering java interfaces as an analogy to that would best explain this . You don't really pass a type , you just pass something that responds to a method ( a trait , if you will ).

提交回复
热议问题