Thursday, February 23, 2012

Python class constructor polymorphism

C++ has this neat class functionality where it will choose the correct class constructor based off what arguments are passed during initialization of the class. Python seems to lack that. I want to be able to pass either a string to the class constructor method OR a reference to an already opened file. It would make my class so much more functional. It seems I'm forced to make one class for each scenario. Well, maybe I could do some type detection and make some decisions in the class constructor based of what is passed, but that's.... hacky?

Also, when did I start getting to a point where I could legit complain about Python OOP features?

No comments:

Post a Comment