Timeline for Should a class know about its subclasses?
Current License: CC BY-SA 3.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 4, 2013 at 2:09 | comment | added | user22815 | Then are agreeing: a visitor needs to know what it is visiting. | |
| Dec 2, 2013 at 20:05 | comment | added | Pavel Voronin | @Sulthan Never say never. Option type is a valid example of the case when supreclass knows about descendant one. But as Jorg said it would be marked as sealed. | |
| Nov 28, 2013 at 10:03 | comment | added | lorus | @JohnGaughan The term "knows" confuses me. The base Node class, of course, does not contain any direct references to its subclasses. But it contains an accept method with a Visitor parameter. And Visitor contains a visit method per each subclass. So, despite Node has no direct references to its subclasses, it "knows" about them indirectly, through Visitor interface. They all coupled together through it. | |
| Nov 28, 2013 at 7:30 | comment | added | user22815 | @Sulthan I have worked with ASTs outside of the classroom, and I believe lorus does not truly understand the question. A Visitor is not a type of node on an AST, it is a separate object. It can and should know about the grammar objects. But a high level AST node should not. | |
| Nov 26, 2013 at 14:39 | comment | added | Sulthan | No, no and no. This is not useful and never a good solution. | |
| Nov 26, 2013 at 14:18 | history | answered | lorus | CC BY-SA 3.0 |