Dedup some code into an abstract base class.