Timeline for Does the signature of a method create a dependency between the implementation of that method, and the code that invokes it?
Current License: CC BY-SA 4.0
19 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 25, 2024 at 1:30 | comment | added | Flater | @Steve The quoted text in the question is not focusing on behavior, it is focusing on the blast radius of a change to the method signature. The cleanliness of code, which is the ultimate goal of the piece being discussed, is irrespective of the precise business rules. That's not to say that we as developers don't need to consider both, we obviously do as marrying the two is arguably the core premise of our role, but that doesn't mean that a guideline on code cleanliness needs to explicitly focus on application behavior at the same time. | |
| Apr 24, 2024 at 16:34 | history | edited | Doc Brown | CC BY-SA 4.0 |
deleted 10 characters in body
|
| Apr 24, 2024 at 8:16 | comment | added | Steve |
@Flater, "For a method, its contract is its signature" - I don't agree with this. The method signature is only a narrow aspect of what a programmer would regard as the "contract". For example, if string String.ToUpper(string) suddenly started returning lowercase due to an implementation change, a programmer would regard the "contract" as different, even though the signature needn't change.
|
|
| Apr 24, 2024 at 6:37 | comment | added | Flater |
@Steve: A contract is very essentially what in the question's quoted text is referred to as "a dependency between the implementation of that method and the code that invokes it". For a method, its contract is its signature. For a class, that's its non-private fields/properties/methods (including their signatures). Whether or not an explicit interface exists to help separate the contract from its implementation is an additional consideration, but a contract exists regardless of whether a corresponding interface exists, as a contract is a very generalized concept w.r.t. component interaction
|
|
| Apr 24, 2024 at 6:26 | comment | added | Steve | @Flater, with this concept of the code "contract", it is rarely clear exactly what the contract is, or where it is specified (if it is explicit at all). It is typically far easier to simply treat a single implementation as mandatory, and any change is assumed to potentially impugn other workings and therefore requires reanalysis and retesting. | |
| Apr 24, 2024 at 5:53 | comment | added | Steve | @Bergi, I don't agree. We write methods typically as a way of organising code, not so that "we don't depend on the implementation". It may be possible to vary the implementation without breaking the caller, but if that works, then it would probably have been just as possible to write the code inline and then vary it - in other words, the implementation is no more free to vary just because it sits behind a method call. | |
| Apr 24, 2024 at 5:47 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 26 characters in body
|
| Apr 24, 2024 at 5:42 | comment | added | Doc Brown | @Flater: still a dependency exists when A calls B, and any change in B has some potential to influence the behaviour of A, maybe in a wanted, maybe in an unwanted manner. It is only a simplistic example what Ousterhood means by "dependency" in the context of that book, don't overinterpret it. | |
| Apr 24, 2024 at 5:29 | comment | added | Flater | @DocBrown: If the contract remains unchanged, but the content of the response is different due to a willful implementation change, then the baseline assumption should be that this change is a conscious one, not one of an unconfirmed risk of introducing bugs into consumers. That's not to say that this doesn't happen in real life, but it should not be a driving factor when considering dependencies. If a method implementation is updated, we can't reasonably be expected to prescribe any guideline to account for any manner of badly doing so. | |
| Apr 24, 2024 at 5:22 | comment | added | Doc Brown | @Bergi: I added some more context from Ousterhood what he is speaking about, then it might become clearer. Fact is, when code A calls a method from B, and B is changed in some way (interface or implementation), one has to consider that A might be influenced by the change in some way. Sometimes this is wanted, sometimes not, still the only guranteed way in A not becoming dependend on B is not to call the method at all. | |
| Apr 24, 2024 at 5:16 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 849 characters in body
|
| Apr 23, 2024 at 19:44 | comment | added | Bergi | "the calling code becomes dependent on the method - on it's signature as well as on it's implementation" - I would disagree with that. We write software with method calls precisely so that we do not depend on a particular implementation, the interface (type of the object, which includes the method signatures but not a concrete implementation) is an abstraction layer and a module boundary. Admittedly, the interface that we depend on also includes contracts (expectations) about what the method should do, which are seldom formalised. | |
| Apr 23, 2024 at 19:13 | comment | added | user3899725 | How can a caller be dependent on an implementation which might not exist? For instance, if calling code depends on a signature defined in an interface, then it is not dependent on that interface's implementation, because it might not exist. The implementation is totally decoupled from the calling code. Calling code can depend on a signature, but I still don't see how it can depend on an its implementation of which it may have zero to many. The whole point of the dependency injection concept to break dependency between calling code and implementation? 'depend on interfaces, not implementations' | |
| Apr 23, 2024 at 18:54 | comment | added | Basilevs | could you comment on the situation when a method can not work without information provided via an argument? If new caller implementation lacks the information, would not that "break" the callee in a certain sense? | |
| Apr 23, 2024 at 17:27 | vote | accept | user3899725 | ||
| Apr 23, 2024 at 19:09 | |||||
| Apr 23, 2024 at 15:44 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 52 characters in body
|
| Apr 23, 2024 at 14:48 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 10 characters in body
|
| Apr 23, 2024 at 13:50 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 348 characters in body
|
| Apr 23, 2024 at 13:15 | history | answered | Doc Brown | CC BY-SA 4.0 |