Timeline for Why is inheritance bad in a Person-Student model?
Current License: CC BY-SA 4.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 16, 2022 at 16:48 | comment | added | Erik Eidt | @Ian, Ok, so are you suggesting either class explosion (statically created base class combinations, like TeacherStudent, PrincipalTeacher, ...) that can be switched between, or else dynamically applying multiple inheritance? This doesn't sound more workable than composition with roles. | |
| Feb 16, 2022 at 16:42 | comment | added | Ian | No, but remember much Object based design teaching was based on UML not how most programming languages do inheritance. Inheritance in a design should but always be implemented by the built in inheritance surport in the programming language. | |
| Feb 16, 2022 at 16:27 | comment | added | Erik Eidt | @M-Pixel, sure, we can restrict things like that in solo or toy projects, but in a business setting, that is a design decision, best made by stakeholders or leaders rather than programmers. | |
| Feb 16, 2022 at 16:08 | comment | added | Erik Eidt | @Ian, that's interesting, so you're proposing adding a TeacherStudent class, and if there's more than those 2 roles, then exponentially more classes? Plus, switching to UML for the programming? | |
| Feb 16, 2022 at 14:28 | comment | added | Ian | The formal UML spec premits inheritance of a object to change based on state changes of the object. | |
| Feb 15, 2022 at 20:35 | comment | added | Joop Eggen | And Teacher and Student already have multiple courses. One could be a teacher of French and a teacher of Maths. It could make sense to have two Teacher-of-Something instances. Without attributes (like course) a "Teacher" is just a role. | |
| Feb 15, 2022 at 20:25 | comment | added | M-Pixel | Note that this is only a problem if your application needs to handle these scenarios. If you can confidently say "when this program is used as intended, a Person object can be expected to always have only the Person role or only the Teacher role and never both or neither", then having an additional Role/Teacher/Student class hierarchy in addition to the Person class would be a case of over-engineering or "unnecessary abstraction". | |
| Feb 15, 2022 at 17:47 | comment | added | Alex | +1 for the statements about modelling with a purpose and not just in a vain effort to reproduce the real world. This is so often overlooked when learning OOP | |
| Feb 15, 2022 at 16:41 | comment | added | Barmar | Silly me, I scanned your answer quickly and didn't even see that. | |
| Feb 15, 2022 at 16:29 | comment | added | Erik Eidt | @Barmar, yeah, when I said "if a teacher takes a course becoming a student", I left it open as to whether that person remained a teacher or not, both are possible, but there's no necessary reason to quit teaching simultaneously with taking a course. | |
| Feb 15, 2022 at 15:53 | comment | added | Barmar | A person can even be both a student and teacher at the same time. You can teach class A while taking class B. | |
| Feb 14, 2022 at 21:15 | vote | accept | Octavian Niculescu | ||
| Feb 14, 2022 at 20:03 | history | edited | Erik Eidt | CC BY-SA 4.0 | added 486 characters in body |
| Feb 14, 2022 at 16:31 | history | edited | Erik Eidt | CC BY-SA 4.0 | added 299 characters in body |
| Feb 14, 2022 at 16:20 | history | edited | Erik Eidt | CC BY-SA 4.0 | added 218 characters in body |
| Feb 14, 2022 at 16:14 | history | edited | Erik Eidt | CC BY-SA 4.0 | added 218 characters in body |
| Feb 14, 2022 at 16:08 | history | edited | Erik Eidt | CC BY-SA 4.0 | added 218 characters in body |
| Feb 14, 2022 at 15:48 | history | answered | Erik Eidt | CC BY-SA 4.0 |