Constructor in an Interface?

前端 未结 11 1071
鱼传尺愫
鱼传尺愫 2020-12-02 06:38

I know it\'s not possible to define a constructor in an interface. But I\'m wondering why, because I think it could be very useful.

So you could be sure that some fi

11条回答
  •  无人及你
    2020-12-02 07:16

    Dependencies that are not referenced in an interfaces methods should be regarded as implementation details, not something that the interface enforces. Of course there can be exceptions, but as a rule, you should define your interface as what the behavior is expected to be. Internal state of a given implementation shouldn't be a design concern of the interface.

提交回复
热议问题