Hollywood Principle

Hollywood Principle

In computer programming, the Hollywood Principle is stated as "don't call us, we'll call you." It has applications in software engineering; see also implicit invocation for a related architectural principle.

Overview

The Hollywood principle is a software design methodology that takes its name from the cliché response given to amateurs auditioning in Hollywood: "Don't call us, we'll call you". It is a useful paradigm that assists in the development of code with high cohesion and low coupling that is easier to debug, maintain and test.

Most beginners are first introduced to programming from a diametrically opposed viewpoint. Programs such as Hello World take control of the running environment and make calls on the underlying system to do their work. A considerable amount of successful software has been developed using the same principles, and indeed many developers need never think there is any other approach. After all, programs with linear flow are generally easy to understand.

As systems increase in complexity, the linear model becomes less maintainable. Consider for example a simple program to bounce a square around a window in your favorite operating system or window manager. The linear approach may work, up to a point. You can keep the moving and drawing code in separate procedures, but soon the logic begins to branch. What happens if the user resizes the window? Or if the square is partially off-screen? Are all those system calls to get such resources as device contexts and interacting with the graphical user interface really part of the solution domain? It would be much more elegant if the programmer could concentrate on the application (in this case, updating the coordinates of the box) and leave the parts common to every application to "something else".

The key to making this possible is to sacrifice the element of control. Instead of your program running the system, the system runs your program. In our example, our program could register for timer events, and write a corresponding event handler that updates the coordinates. The program would include other callbacks to respond to other events, such as when the system requires part of a window to be redrawn. The system should provide suitable context information so the handler can perform the task and return. The user's program no longer includes an explicit control path, aside from initialization and registration.

Event loop programming, however, is merely the beginning of software development following the Hollywood principle. More advanced schemes such as event-driven object-orientation go further along the path, by software components sending messages to each other and reacting to the messages they receive. Each message handler merely has to perform its own local processing. It becomes very easy to unit test individual components of the system in isolation, while integration of all the components typically does not have to concern itself excessively with the dependencies between them.

Software architecture that encourages the Hollywood principle typically becomes more than "just" an API - instead, it may take on more dominant roles such as a software framework or container. In the Windows world, MFC is an example of a framework for C++ developers to interact with the Windows environment, while .NET framework is touted as a framework for scalable enterprise applications. On the Java side, the Enterprise JavaBeans specification describes the responsibilities of an EJB container, which must support such enterprise features as remote procedure calls and transaction management.

All of these mechanisms require some cooperation from the developer. To integrate seamlessly with the framework, the developer must produce code that follows some conventions and requirements of the framework. This may be something as simple as implementing a specific interface, or, as in the case of EJB, a significant amount of wrapper code, often produced by code generation tools.

Recent paradigms

More recent paradigms and design patterns go even further in pursuit of the Hollywood principle. Inversion of control for instance takes even the integration and configuration of the system out of the application, and instead performs dependency injection.

Again, this is most easily illustrated by an example. A more complex program such as a financial application is likely to depend on several external resources, such as database connections. Traditionally, the code to connect to the database ends up as a procedure somewhere in the program. It becomes difficult to change the database or test the code without one. The same is true for every other external resource that the application uses.

Various design patterns exist to try to reduce the coupling in such applications. In the Java world, the Service locator pattern exists to lookup resources in a directory, such as JNDI. This reduces the dependency - now, instead of every separate resource having its own initialization code, the program depends only on the service locator. This is better, but still not ideal.

Inversion of control

Inversion of control containers take the next logical step. In this example, the configuration and location of the database (and all the other resources) is kept in a configuration file external from the code. The container is responsible for resolution of these dependencies, and delivers them to the other software components - for example by calling a setter method. The code itself does not contain any configuration. Changing the database, or replacing it with a suitable mock object for unit testing, becomes a relatively simple matter of changing the external configuration. Integration of software components is facilitated, and the individual components get ever closer to the Hollywood principle.


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Hollywood, Los Angeles, California — Hollywood is a district in the city of Los Angeles, California, situated west northwest of Downtown Los Angeles. [ [http://www.laalmanac.com/LA/lamap2.htm City of Los Angeles Map Larger View ] ] Due to its fame and cultural identity as the… …   Wikipedia

  • Hollywood — This article is about the district in Los Angeles. For information about the American film industry, see Cinema of the United States. For other uses, see Hollywood (disambiguation). Hollywood   District of Los Angeles   …   Wikipedia

  • Hollywood blacklist — Hollywood Ten redirects here. For the 1950 short documentary film, see The Hollywood Ten. thumb|right|300px|Protestors opposing the jailing of the Hollywood Ten in 1950 (from the 1987 documentary Legacy of the Hollywood Blacklist ).The Hollywood… …   Wikipedia

  • Disney's Hollywood Studios — Disney s Hollywood Studios …   Wikipedia

  • Classical Hollywood cinema — Golden Hollywood (First row, left right) Greta Garbo, Humphrey Bogart, Lauren Bacall, Clark Gable, Katharine Hepburn, Fred Astaire, Ginger Rogers, Marlon Brando, Marx Brothers, Joan Crawford (Second row, left right) Jo …   Wikipedia

  • List of Disney's Hollywood Studios attractions — Action on the set of Indiana Jones Epic Stunt Spectacular! …   Wikipedia

  • Disney's Hollywood Studios attraction and entertainment history — Disney s Hollywood Studios consists of five themed areas. Major attractions are listed below.Hollywood BoulevardHollywood Boulevard is lined with shops selling Disney merchandise and food. This is also the location of Disney Pixar s Block Party… …   Wikipedia

  • The Noah's Ark Principle — Das Arche Noah Prinzip Directed by Roland Emmerich Produced by Wolfgang Längsfeld Hans Weth Peter Zenk Execu …   Wikipedia

  • Inversion of control — In software engineering, Inversion of Control (IoC) is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to procedural programming. In traditional… …   Wikipedia

  • Mach-II — Infobox Software name = Mach II caption = We re Community Driven genre = web application framework developer = [http://www.greatbiztools.com GreatBizTools, LLC] |source model = Open source latest release version = 1.6 Beta latest release date =… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”