What Is a Framework?

 <  Day Day Up  >  

Hand-in-hand with the concept of code reuse is the concept of standardization , which is sometimes called plug-and-play . The idea of a framework revolves around these plug-and-play and reuse principles. One of the classic examples of a framework is a desktop application. Let's take an office suite application as an example. The document editor that I am currently using (Microsoft Word) has a menu bar that includes multiple menu options. These options are similar to those in the presentation package (Microsoft PowerPoint) and the spreadsheet software (Microsoft Excel) that I also have open. In fact, the first six menu items (File, Edit, View, Insert, Format, and Tools) are the same in all three programs. Not only are the menu options similar, but the first toolbar looks remarkably alike as well (New, Open , Save, and so on). Below the toolbars is the document area ”whether it be for a document, a presentation, or a spreadsheet. The common framework makes it easier to learn various applications within the office suite. It also makes a developer's life easier by allowing maximum code reuse.

The fact that all these menu bars have a similar look and feel is obviously not an accident . In fact, when you develop in most integrated development environments, on a certain platform like Microsoft Windows, for example, you get certain things without having to create them yourself. When you create a window in a Windows environment, you get elements like the main title bar and the file close button in the top-right corner. When you double-click on the main title bar, the screen always minimizes/maximizes. When you click on the close button in the top-right corner, the application always terminates. This is all part of the framework. Figure 8.1 is a screenshot of a word processor. Note the menu bars, toolbars, and other elements that are part of the framework.

Figure 8.1. A word processing framework.

graphics/08fig01.jpg

A word processing framework generally includes operations such as creating documents; opening documents; saving documents; cutting, copying, and pasting text; searching through documents; and so on. To use this framework, a developer must use a predetermined interface to create an application. This predetermined interface conforms to the standard framework, which has two obvious advantages. First, as we have already seen, the look and feel are consistent, and the end users do not have to learn a new framework. Second, a developer can take advantage of code that has already been written and tested (and this testing issue should not be underestimated). Why write code to create a brand new Open dialog when one already exists and has been thoroughly tested ? In a business setting, when time is critical, people do not want to have to learn new things unless it is absolutely necessary.

Code Reuse Revisited

In Chapter 7, we talked about code reuse as it pertains to inheritance ”basically one class inheriting from another class. This chapter is about frameworks and reusing whole or partial systems.


You might next wonder how you use the dialog box provided by the framework. The answer is simple: You follow the rules that the framework provides you. And where might you find these rules? The rules for the framework are found in the documentation. The person or persons who wrote the class, classes, or class libraries should have provided documentation on how to use the public interfaces of the class, classes, or class libraries (at least we hope). In many cases, this takes the form of the application programming interface (API).

For example, to create an applet in Java, you would bring up the API documentation for the Applet class and take a look at the public interfaces it presents . Figure 8.2 shows a part of the Java API. By using these APIs, you can create a valid Java applet and conform to required standards. If you follow these standards, your applet will be set to run in Java-enabled browsers.

Figure 8.2. API documentation.

graphics/08fig02.jpg

 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net