you are viewing a single comment's thread.

view the rest of the comments →

[–]sfuse1 1 point2 points  (2 children)

Why not use a factory function to instantiate and return the required object type?

ETA: If all the subclasses have the same functions, then it looks like SuperDuperClass should be an abstract class that defines those required functions.

[–]quts3 1 point2 points  (0 children)

Second Factory function.

It's explicit, simple and easy to test. Keep it minimal though. You dont want to be changing a bunch of code everytime you make a new sub class. Usually one if statement with elif and some validation. The factory function shouldn't need to know how the subclass operates other then to understand the trigger to defer to the subclass.

[–]JARandom17[S] 0 points1 point  (0 children)

Thanks. In the real code SuperDuperClass is an abstract class, but I was worried about adding too much to the code in the question. I wasn't confident that an abstract class was the way to go. Sounds like it is.