<< Chapter < Page Chapter >> Page >

A software framework, in computer programming, is an abstraction in which common code providing generic functionality can be selectivelyoverridden or specialized by user code providing specific functionality.

Frameworks are a special case of software libraries in that they are reusable abstractions of code wrapped in a well-defined API, yet they contain some keydistinguishing features that separate them from normal libraries.

Software frameworks have these distinguishing features that separate them from libraries or normal user applications:

  1. inversion of control - In a framework, unlike in libraries or normal user applications, the overall program's flow of controlis not dictated by the caller, but by the framework.
  2. default behavior - A framework has a default behavior. This default behavior must actually be some useful behavior and not a seriesof no-ops.
  3. extensibility - A framework can be extended by the user by selective overriding of framework code in order to provide specificfunctionality
  4. non-modifiable framework code - The framework code, in general should not normally be modified by the user. Users can extend theframework, but normally should not modify its code.

In short, a software framework is a computer program that helps you to write computer programs.

The Processing PDE fits all of these characteristics of a framework.

Inversion of control

By default, the overall flow of control of a Processing sketch is beyond the control of the programmer. When the sketch starts running, the setup method will be called once and (by default) the draw method will be called repeatedly at a default rate of 60 calls per second.

A small window will be displayed in the default Java display mode. If you haven't overridden the draw method to control the contents of that window, it will look something like that shown in Image 1 .

Image 1. default display window.

Default display window
Image 1. Default display window.

Create the body of a class

Image 2 shows a screen shot of the PDE with program code showing in the leftmost tab.

Image 2. the pde.

The PDE.
Image 2. The PDE.

When you create a new sketch in the PDE and enter code in the leftmost tab, you are actually writing the body of a new class witha class name that matches the name of the tab. The code that you see in Image 2 , for example, constitutes the body of a new class named Cars .

Override setup and draw methods

In general, you need to override the methods named setup and draw in the body of this class. It is the code that you write in these two overridden methods that controls the behavior of the sketch.

The setup method will be called once when you click the run button. You should place any code that needs to be executed to initialize the state of the sketch in this method. Often this code willinitialize variables, instantiate new objects, etc.

After that, by default, the draw method will be called repeatedly until you terminate execution of the sketch. You need to write codein the draw method that controls the ongoing behavior of the sketch. Often, this code will call methods on existing objects, modify thecontents of variables, instantiate and call methods on new objects, etc.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, The processing programming environment. OpenStax CNX. Feb 26, 2013 Download for free at http://cnx.org/content/col11492/1.5
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'The processing programming environment' conversation and receive update notifications?

Ask