Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach

web.firat.edu.tr
from web.firat.edu.tr More from this publisher
21.08.2013 Views

Figure 16.3 Single inheritance JFrame Circle Game JFrame Thread Game Figure 16.4 Multiple inheritance (supported in C++ but not in Java) 16.8 Multiple interfaces 231 Sometimes we would like a class to inherit from more than one superclass as described in the following class header and shown in Figure 16.4. public class Game extends JFrame, Thread // error But this heading is wrong because it attempts to extend two classes. This would be called multiple inheritance. Some languages, such as C++, permit multiple inheritance while Java does not. Multiple inheritance allows a class to inherit sets of methods from a number of classes, and it is therefore potentially very powerful. If we think about classification systems in science and nature, it is often the case that objects belong to more than one class. We humans, for example, belong to one gender class, but also to a class that likes a particular type of music. So we all belong in one inheritance tree for gender, another for musical taste, another for mother tongue, and so on. Interfaces provide a way of emulating a facility similar to multiple inheritance. This is because, while a class can only extend a single class, it can implement any number of interfaces. Multiple interfaces are illustrated in Figure 16.5. This example is coded in Java as follows: public class Game extends JFrame implements InterfaceA, InterfaceB If Game inherited from InterfaceA and InterfaceB, it would inherit a set of methods from InterfaceA and InterfaceB. But instead Game is implementing interfaces InterfaceA and InterfaceB, and these interfaces have no methods on offer.

232 Chapter 16 ■ Programming in the large JFrame Figure 16.5 Multiple interfaces InterfaceA Game What this means is that class Game agrees to provide the methods described in InterfaceA and InterfaceB – that Game has agreed to conform to certain behavior. The code for implementing InterfaceA and InterfaceB has to be written as part of the class Game. 16.9 ● Separate compilation InterfaceB A programming language is ill suited for the development of large, complex programs if it does not provide facilities for the separate compilation of program modules. Large programs must necessarily be developed by teams of programmers; individual programmers must be able to work independently and at the same time be able to access programs written by other members of the team. Programming language support is required for the integration of routines that have been developed separately. Additional support in this area is often provided by environmental tools, such as linkers, cross-reference generators, file librarians and source code control systems. What support should the programming language itself provide? We suggest the following: ■ independent compilation of program modules ■ easy access to libraries of precompiled software ■ the ability to integrate together components written in different languages ■ strong type checking across module boundaries ■ the ability to avoid the unnecessary recompilation of precompiled modules. One of the foremost reasons for the continued popularity of Fortran is the tremendous resource of reusable software available to scientists and engineers through the readily accessible libraries of scientific and engineering subroutines. Fortran provides independent compilation of modules at the subroutine level and easy access to library routines but performs no run-time checking of calls to external routines. It is the responsibility of the programmer to check that the correct number and type of parameters are used in the calling program. Java and similar languages provide far greater support for separate compilation than Fortran. Classes may be compiled as separate modules with strong type checking across module boundaries to ensure that they are used in accordance with their specifications. The specification and implementation of a class may be compiled in two separate parts.

232 Chapter 16 ■ <strong>Programming</strong> in the large<br />

JFrame<br />

Figure 16.5 Multiple interfaces<br />

<br />

InterfaceA<br />

Game<br />

What this means is that class Game agrees to provide the methods described in<br />

InterfaceA and InterfaceB – that Game has agreed to con<strong>for</strong>m to certain behavior.<br />

The code <strong>for</strong> implementing InterfaceA and InterfaceB has to be written as part of<br />

the class Game.<br />

16.9 ● Separate compilation<br />

<br />

InterfaceB<br />

A programming language is ill suited <strong>for</strong> the development of large, complex programs<br />

if it does not provide facilities <strong>for</strong> the separate compilation of program modules. Large<br />

programs must necessarily be developed by teams of programmers; individual programmers<br />

must be able to work independently and at the same time be able to access<br />

programs written by other members of the team. <strong>Programming</strong> language support is<br />

required <strong>for</strong> the integration of routines that have been developed separately. Additional support<br />

in this area is often provided by environmental tools, such as linkers, cross-reference<br />

generators, file librarians and source code control systems. What support should the<br />

programming language itself provide? We suggest the following:<br />

■ independent compilation of program modules<br />

■ easy access to libraries of precompiled software<br />

■ the ability to integrate together components written in different languages<br />

■ strong type checking across module boundaries<br />

■ the ability to avoid the unnecessary recompilation of precompiled modules.<br />

One of the <strong>for</strong>emost reasons <strong>for</strong> the continued popularity of Fortran is the tremendous<br />

resource of reusable software available to scientists and engineers through the<br />

readily accessible libraries of scientific and engineering subroutines. Fortran provides<br />

independent compilation of modules at the subroutine level and easy access to library<br />

routines but per<strong>for</strong>ms no run-time checking of calls to external routines. It is the<br />

responsibility of the programmer to check that the correct number and type of parameters<br />

are used in the calling program.<br />

Java and similar languages provide far greater support <strong>for</strong> separate compilation than<br />

Fortran. Classes may be compiled as separate modules with strong type checking across<br />

module boundaries to ensure that they are used in accordance with their specifications.<br />

The specification and implementation of a class may be compiled in two separate parts.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!