Timeline for Is it logical to not use inheritance because the function is critical?
Current License: CC BY-SA 4.0
33 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 12, 2024 at 14:17 | audit | First questions | |||
| Jan 12, 2024 at 14:17 | |||||
| Dec 22, 2023 at 23:54 | comment | added | Jon Watte | Sounds like the implementation inheritance is the real problem. You might want to invert control, make the base class be final and non virtual, and pass in one or more strategies that vary whatever it is that needs varying. The base class for the strategies should be an interface (or in C++, pure abstract base class) | |
| Dec 21, 2023 at 23:59 | comment | added | Jeremy Friesner | It sounds to me what is really desired here is some sort of automated unit-testing mechanism, such that if someone did mess up the implementation of their subclass, that error would be caught quickly and cheaply during the next daily-test run. With that in place, you wouldn't have to worry so much about people making mistakes, because the mistakes would be caught. | |
| Dec 21, 2023 at 23:32 | comment | added | Adrian McCarthy | Is it possible the method in question is doing too much? Are the unusual implementations mostly different than the common ones or only subtly different? Perhaps the portion that actually varies (and thus should be tailored) should be broken out into a (possibly pure) virtual method and the boilerplate should just be a non-virtual method in the base class. If the concern behind the rule is warranted, that would do more to focus people on the key difference, reduce the need for cloning implementations, and possibly reduce the test burden. | |
| Dec 21, 2023 at 16:05 | comment | added | JimmyJames | "they don't blindly inherit the function" and what stops the developer from blindly copy-pasting the wrong implementation? Getting things right is a real concern but this isn't a real solution. Code reviews and testing should help, though. | |
| Dec 21, 2023 at 11:35 | answer | added | Mateen Ulhaq | timeline score: 0 | |
| Dec 21, 2023 at 5:17 | history | protected | gnat | ||
| Dec 21, 2023 at 4:52 | answer | added | jmoreno | timeline score: 2 | |
| Dec 21, 2023 at 0:11 | answer | added | Peter - Reinstate Monica | timeline score: 0 | |
| Dec 20, 2023 at 23:24 | comment | added | Mark Rogers | You don't always want to resuse code, but in this case if you wanted to change the basic functionality you would have to change it in 98 places. | |
| Dec 20, 2023 at 21:31 | history | edited | Zack Light | CC BY-SA 4.0 | Emphasize main concern and fix typo |
| Dec 20, 2023 at 19:34 | comment | added | gnasher729 | If all you want is a reminder, add subclass methods that just call the superclass with a comment, so if I copy one of your subclasses as the first step to create my own, I start with a big reminder. Actually duplicating the baseclass code is asking for trouble. | |
| Dec 20, 2023 at 18:38 | history | edited | Zack Light | CC BY-SA 4.0 | Distinguish question from suggested duplicates by bringing in the question of balance. |
| Dec 20, 2023 at 18:33 | comment | added | Zack Light | I totally buy in composition if the function implementation has decent variance. Since our implementation is word-by-word the same for, say, 98 out of 100 sub-classes, I wasn't sure if it's fair to require the 98 to compose instead of inherit. | |
| Dec 20, 2023 at 18:23 | comment | added | Zack Light | @bitmask It's in CPP | |
| Dec 20, 2023 at 17:52 | comment | added | Peter - Reinstate Monica | <sarcasm>Repository size and, more generally, disk space! Every byte is sacred!</sarcasm> | |
| Dec 20, 2023 at 12:26 | comment | added | bitmask | I think that depends on the language used. What is your project written in? | |
| Dec 20, 2023 at 12:00 | answer | added | Johannes | timeline score: 1 | |
| Dec 20, 2023 at 9:36 | answer | added | sfiss | timeline score: 1 | |
| Dec 20, 2023 at 8:55 | answer | added | Doc Brown | timeline score: 11 | |
| Dec 20, 2023 at 7:29 | history | became hot network question | |||
| Dec 20, 2023 at 6:15 | review | Close votes | |||
| Dec 25, 2023 at 3:04 | |||||
| Dec 20, 2023 at 6:00 | comment | added | gnat | TL;DR of duplicate: both inheritance and function duplication are wrong way to handle problems like this. You need to use composition which provides reasonable balance of control, safety and code reuse (speaking from personal experience here, because I've been in situation that sounds exactly as you describe and changing inheritance to composition worked like a charm) | |
| Dec 20, 2023 at 5:59 | comment | added | gnat | Does this answer your question? Why should I prefer composition over inheritance? | |
| Dec 20, 2023 at 5:54 | answer | added | DavidT | timeline score: 17 | |
| Dec 20, 2023 at 3:00 | comment | added | T. Sar | This is a case where unit tests can solve a lot of issues without those strange, arbitrary rules. | |
| Dec 20, 2023 at 0:28 | answer | added | candied_orange | timeline score: 54 | |
| Dec 20, 2023 at 0:13 | answer | added | Telastyn | timeline score: 7 | |
| Dec 19, 2023 at 23:57 | answer | added | Greg Burghardt | timeline score: 27 | |
| Dec 19, 2023 at 23:33 | answer | added | CrazyFrog | timeline score: -4 | |
| Dec 19, 2023 at 22:29 | comment | added | Kilian Foth | That sounds like a post-hoc argument that some middle-level decision maker invented, maybe after a particularly traumatic failure that prevented them from properly generalizing the "lessons learnt"from that incident. | |
| S Dec 19, 2023 at 22:26 | review | First questions | |||
| Dec 19, 2023 at 23:57 | |||||
| S Dec 19, 2023 at 22:26 | history | asked | Zack Light | CC BY-SA 4.0 |