0

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.

choxsword
  • 3,187
  • 18
  • 44
  • 1
    *"we should be encouraged to split functions into small interfaces"*: what happens to using interfaces simply for defining types? Interfaces are not about just pieces of behavior-specific APIs, or, worse, merely to solve for multiple inheritance. If you implement `Set`, you implement a type. If the concept of "set" evolves to include the notion of "stream", then the type `Set` has evolved. Default methods or breaking existing implementations will boil down to practical ways of dealing with the consequences of type evolution. It may be about perspectives, but I think **ISP** here goes too far. – ernest_k Jul 11 '21 at 14:40
  • @jaco0646 seems to be the same question, but without a conclusion. – choxsword Jul 11 '21 at 15:09
  • What sort of a conclusion are you expecting? – jaco0646 Jul 12 '21 at 15:22

1 Answers1

-2

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.

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
  • But we can add new methods by introducing new interfaces. What's more, since such mechanism is supported in language level, it tends to be abused. For example, people would design large interfaces in their origin design, not for the backward compatibility reason. – choxsword Jul 11 '21 at 14:32
  • 1
    If we were to suppose that new interface methods were added without default implementations, i.e., forcing all existing code to be updated and recompiled; would you say that it did not conflict with ISP? Or is this answer implying that the conflict stems from the fact that the new methods have default implementions? Because it can be argued that default methods are added within the definition of the interface's type. – ernest_k Jul 11 '21 at 14:58
  • This answer sounds like it is addressing the OCP rather than ISP. The ISP is about coupling & cohesion. You can introduce a method in hindsight without increased coupling or decreased cohesion. (Of course you can violate both as well, that's up to you.) – jaco0646 Jul 11 '21 at 15:02