return an object of a different class

Ben Finney ben+python at benfinney.id.au
Wed Feb 16 02:22:36 EST 2011


spam at uce.gov writes:

> > Perhaps you want those classes to inherit from your base class. Have
> > you done the Python tutorial? It covers inheritance and how to use
> > it.
>
> Yes, I have done subclasing before, and yes ThingyTypeA and B should
> be subclassing Thingy

Then your example still gives no indication why inheritance (allowing
the common behaviour to be in the base class), along with a factory
function (allowing the input data to determine which class gets
instantiated), is not sufficient.

-- 
 \     “When people believe that they have absolute knowledge, with no |
  `\     test in reality, this [the Auschwitz crematorium] is how they |
_o__)             behave.” —Jacob Bronowski, _The Ascent of Man_, 1973 |
Ben Finney



More information about the Python-list mailing list