Timeline for How to design relationships with constraints on subclass type?
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 12, 2023 at 13:50 | history | edited | Christophe | CC BY-SA 4.0 |
added 6 characters in body
|
| Nov 12, 2023 at 13:48 | comment | added | Christophe | @MehdiCharife Indeed, this is a valid approach as well! Some languages such as curent C# or Java will let you do covarianc. In C++, it works only with raw pointers. In all other cases, you'll have to return a smart pointer (or a collection) to the common Report ancestor and use polymorphism. In Python, there is a similar restriction as soon as you use a collection return. Of course in those languages you could use an abstract factory for returning families of related objects (e.g. JobA and ReportA, or JobA and a builder of ReportA). Nevertheless, you'd rely on good behavior of the objects. | |
| Nov 12, 2023 at 13:03 | history | edited | Christophe | CC BY-SA 4.0 |
deleted 10 characters in body
|
| Nov 12, 2023 at 12:30 | comment | added | Mehdi Charife |
In the case where covariance is not supported, I think one can make JobA and JobB both abstract classes and override their Report returning methods by calling an abstract method that returns the corresponding desired Report type.
|
|
| Mar 26, 2022 at 22:54 | history | edited | Christophe | CC BY-SA 4.0 |
added 2 characters in body
|
| Mar 26, 2022 at 20:38 | history | edited | Christophe | CC BY-SA 4.0 |
added 135 characters in body
|
| Mar 26, 2022 at 20:21 | history | edited | Christophe | CC BY-SA 4.0 |
added 135 characters in body
|
| Mar 26, 2022 at 19:05 | history | answered | Christophe | CC BY-SA 4.0 |