3 ms·
It's interesting, but I can see it leading to much frustration when, as an overrider, you don't want it to run that before/after code. The thing is, the develo
by icebraining 9y ago
It's interesting, but I can see it leading to much frustration when, as an overrider, you don't want it to run that before/after code.
The thing is, the developer doing the overriding generally has more information about the final system than the original - after all, the code is more specific. So taking away their power is generally problematic.
I could see it being useful if it was optional. Something like:
class ScaryMonster extends GameObject {
void render(Renderer renderer) {
super(function() {
renderer.drawImage(Images.SCARY_MONSTER);
});
}
}
- deleted 9y ago[deleted]
- barrkel 9y agoAnother perspective: the developer doing the overriding doesn't in fact have more information; they don't know the future plans of the developer of the class they're overriding, and they don't know about the usage models of other descendants of the class and how they'll affect evolution into the future. The more "power" they use, the more likely they'll be left behind on a version bump. Implementation inheritance means accepting an extremely tight coupling to the ancestor, and overriding is the main mechanism of coupling. Coupling means correlated changes, and when the developers of the ancestor and descendant are in different organizations, it means versioning risk. This is an argument for very careful selection of methods available for overriding, and strictly limiting the choices of the descendant, funneling them into designed-for usage modes. Versioning is single biggest reason why C# elected to make methods non-virtual by default, where Java makes them virtual by default. Breaking all the clients of your code because of an implementation design change isn't very desireable, thus limiting the surface area for coupling is usually a good idea. If ancestors and descendants are in the same repository so upgrades of definition site and use site can be coordinated, or the probability of design change in the ancestor is low, then these concerns are more relaxed. But they're valid in many situations.
- icebraining 9y agoThe library developers can provide that information without enforcing it. For example, in Python any method starting with an underscore is considered private and liable to be changed or removed, but the language doesn't treat them in a special way. Enforcement mechanisms don't have anything to do with passing information, but with removing liability (not necessarily legal - might only be social) from the original developers. They're effectively an EULA.
- coldtea 9y ago>It's interesting, but I can see it leading to much frustration when, as an overrider, you don't want it to run that before/after code. It's about ensuring the invariants the parent class needs -- not giving subclasses freedom to do whatever they want is meant as a feature. This allows library designers to design more future proof APIs (since they control more invariants of how they're gonna be extended), and to prevent users of their libs from shooting themselves in the foot.
- kuschku 9y agoAnd it requires users that want to override it (a common issue with final stuff on Android) to use native extensions to patch the memory of the parent class at runtime (or use other forms of reflection).
- msangi 9y agoIs there any reason it is common in Andoid to want to override final stuff? Is it because of a design issue in the Android libraries or to try and circumvent some limitations that might have some reasons to exist?
- kuschku 9y agoIt is because often you need to do stuff that the system doesn’t allow on older versions. As updates are rarely ever applied, you have to deal with 10 year old versions frequently. So you use these tricks to get the same functionality on old versions. Sometimes you also need to do the same on modern versions, because Google releases UI libraries where everything is final and internal, and so you either have to fork a library with hundredthousands of LOC, or you gotta use reflection. As on android every library is bundled statically, there’s no risk of anything breaking either.
- coldtea 9y ago>(It is because often you need to do stuff that the system doesn’t allow on older versions. As updates are rarely ever applied, you have to deal with 10 year old versions frequently. That's not a programming problem that this capability allows us to solve though. That's a management/market/etc problem, that necessitates that we use this method as a kludge to bypass it.