O'Reilly logo

Exercises in Programming Style by Cristina Videira Lopes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14

Hollywood

image

14.1 Constraints

  • Larger problem is decomposed into entities using some form of abstraction (objects, modules or similar).
  • The entities are never called on directly for actions.
  • The entities provide interfaces for other entities to be able to register callbacks.
  • At certain points of the computation, the entities call on the other entities that have registered for callbacks.

14.2 A Program in this Style

  1 #!/usr/bin/env python
  2 import sys, re, operator, string
  3
  4 #
  5 # The "I'll call you back" Word Frequency Framework
  6 #
  7 class WordFrequencyFramework:
  8 _load_event_handlers = []
  9 _dowork_event_handlers = []
 10 _end_event_handlers ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required