Skip to content

Commit 4524175

Browse files
committed
Design Patterns: Reword advice on imports of subclasses
I had totally overlooked the fact that this doesn't only apply to abstract classes.
1 parent 60ea9ce commit 4524175

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/ql-design-patterns.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ You can, of course, do the same without the `::Range` pattern, but it's a little
7474
If you only had an `abstract class EscapeFunction { ... }`, then `JsEscapeFunction` would need to be implemented in a slightly tricky way to prevent it from extending `EscapeFunction` (instead of refining it). You would have to give it a charpred `this instanceof EscapeFunction`, which looks useless but isn't. And additionally, you'd have to provide trivial `none()` overrides of all the abstract predicates defined in `EscapeFunction`. This is all pretty awkward, and we can avoid it by distinguishing between `EscapeFunction` and `EscapeFunction::Range`.
7575

7676

77-
## Importing all subclasses of abstract base class
77+
## Importing all subclasses of a class
7878

79-
When providing an abstract class, you should ensure that all subclasses are included when the abstract class is (unless you have good reason not to). Otherwise you risk having different meanings of the abstract class depending on what you happen to import.
79+
Importing new files can modify the behaviour of the standard library, by introducing new subtypes of `abstract` classes, by introducing new multiple inheritance relationships, or by overriding predicates. This can change query results and force evaluator cache misses.
8080

81-
One example where this _does not_ apply: `DataFlow::Configuration` and its variants are abstract, but we generally do not want to import all configurations into the same scope at once.
81+
Therefore, unless you have good reason not to, you should ensure that all subclasses are included when the base-class is (to the extent possible).
82+
83+
One example where this _does not_ apply: `DataFlow::Configuration` and its variants are meant to be subclassed, but we generally do not want to import all configurations into the same scope at once.

0 commit comments

Comments
 (0)