I’ve got a piece of third party software containing classes that I want to modify by subclassing. My problem is that one of the third party classes is not accessed directly but returned by the third party class through a method call.
So:
factory = ThirdParty.Factory()
node = factory.getNode() #node is an instance of class ThirdParty.Node
I however want the Factory to return my subclassed version of node
nodeSubclass = factory.getNode()
Now I'm thinking can make a subclass of Factory and can override its getNode() method like so:
factorySubclass = MyFactorySubclass()
nodeSubclass = factorySubclass.getNode()
but I am not sure how I convert the instance of node returned within that to an instance of my NodeSubclass with all its attributes but also the methods I override and add.
I'm not even sure its possible to turn an instance into a subclass of that instance?
Thanks