Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 2
    I am pretty sure if this is a good solution depends heavily of what A, B, processA and processB represent, how often they are supposed to be changed, how the whole class hierarchy looks like. It also depends on the context of where the process() method will be called, and if we are writing a throw-away program or a reusable library, and a dozen other things. I don't like this kind of contrived examples where anyone can pick the interpretation he/she likes best. Commented Oct 1, 2019 at 11:46
  • Maybe more concrete example: Let's say we have parent A class. B and C classes inherits from A. Additionally B implements IDisposable. C doesn't implement IDisposable because it doesn't anything to clean-up. List<A> contains some B and C. I want to dispose all B instances to not make memory leaks. I don't want to force to implement IDisposable on all A children when not every child have some resources to clean-up. Commented Oct 1, 2019 at 12:03
  • Either have C be (vacuously) IDisposable anyway, or introduce your own finalize() method into A with a no-op default implementation. Commented Oct 1, 2019 at 12:05