Implementing the third solution: subclassing with class generator