choxsword
choxsword

Reputation: 3369

does default interface violate the Interface Segregation Principle?

in this question the author gives some reasons about why the default keyword is introduced into java language. One reason provided is to support the optional method.

However, taking ISP into consideration, no client should be forced to depend on methods it does not use.

(from wikipedia) In the field of software engineering, the interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use.[1] ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them. Such shrunken interfaces are also called role interfaces.

From my point of view, we should be encouraged to split functions into small interfaces, without puting everything into single interface by the default trick.

Upvotes: 0

Views: 205

Answers (1)

Zabuzard
Zabuzard

Reputation: 25923

Simple and short:

Yes, it conflicts with the ISP.

But there is no other choice if you want to introduce a method in hindsight, after already designing the original interface and having people implement it all over the world.

Upvotes: -2

Related Questions