Abstract classes?

Adrian Eyre a.eyre at optichrome.com
Thu Feb 17 09:42:18 EST 2000


> [snip]
> What does the Python community in general think of this?
> Also, any general critiques of this code?
> [snip]

I do this kind of thing all the time. Self-documenting code is
good, especially when you're too lazy to do real documentation.
It might be a good idea (to make it even clearer) to stick a
docstring in the "virtual" methods to give a hint to subclassers
as to what they're for.

e.g.

class SpamContainer:
	def getSpamSlices(self):
		"""This function should return the number of slices
		of spam the subclass contains"""
		raise RuntimeError, "This method should be overriden in derived class"

class CanOfSpam(SpamContainer):
	def getSpamSlices(self):
		return 25

class BarrelOfSpam(SpamContainer):
	def getSpamSlices(self):
		return 42000

Unfortunately, spam has been declared obsolete in the UK :(

-----------------------------------------------------------------
Adrian Eyre <a.eyre at optichrome.com> - http://www.optichrome.com 





More information about the Python-list mailing list