Return to Home Page
      Blog     Consulting     Seminars     Calendar     Books     CD-ROMS     Newsletter     About     FAQ      Search
 

Wouldn't it be nicer to prototype customize1()
and customize2() in the base class, as a way to
document how they should be over-ridden by their
subclasses. Something like:

class ApplicationFrameWork:
...
def customize1(): raise NotImplementedError
def customize2(): raise NotImplementedError

This seems to be the Python idiom for a "virtual function."

f  e  x


Expanding on jmd's entry number 1 comment: I don't believe the intent of the Template Method pattern is to always *require* execution -- so only methods in the framework that you wish to require would have the NotImplementedError exception. The others would probably have pass ...(?)

On a different matter: Why do you have

  
    self.__templateMethod()
  def __templateMethod(self):

Is it for clearer exposition or code maintenance?
Won't the following be the same behavior?



class ApplicationFramework:
  def __init__(self):
    for i in range(5):
      self.customize1()
      self.customize2()

# Create a "application":
class MyApp(ApplicationFramework):
  def customize1(self):
    print "Nudge, nudge, wink, wink! ",
  def customize2(self): 
    print "Say no more, Say no more!"

MyApp()
f  e  x


Why are the customize functions being called five times each? I suspect you wanted to harvest numbered customize functions and call them once each:


i = 0
while 1:
  i += 1
  customizingFunction = 'customize%d' % (i)
  if hasattr(self, customizingFunction): 
    apply(getattr(self, customizingFunction))
  else: 
    break

Better yet, call all bound methods with names beginning with 'customize'...

f  e  x



Add your comment below. Use an empty line between each paragraph. Paragraphs will be automatically formatted, and single carriage returns will be respected. Use <code> to begin a code block, and </code> to end a code block. Your email address will not be visible to spam harvesters or used in any way except to contact you with further questions.

Your Email Address:

Search     Home     WebLog     Consulting     Seminars     Calendar     Books     CD-ROMS     Newsletter     About     Contact     Site Design     Server Maintenance     Powered by Zope
©2007 MindView, Inc.