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

CHAPTER 12 This chapter explains: 12.1 ● Introduction Experienced programmers draw on half-remembered memories of software structures that they have used themselves or seen used in the past. An example of a simple programming pattern is the design of a program to find the largest number in an array of numbers. The simplest algorithm uses a variable to record the largest value that has yet been encountered. The program starts at the beginning of the array and proceeds item by item, examining each number, updating this variable as necessary: largest = list[0] index = 0 while index largest then largest = list[index] end if index = index + 1 end while Design patterns ■ how to use design patterns during development ■ several major design patterns ■ some valuable anti-patterns. This is clearly a small piece of program that is easily constructed by any experienced programmer, but to novice programmers, seeing this is something of a revelation. And once seen, the programmer never forgets it. Or at least the programmer remembers the idea of what is needed, rather than the detail. This is a software pattern. Over a >

152 Chapter 12 ■ Design patterns period of time, experienced programmers build up a large repertoire of memories of programming patterns such as this one. A number of patterns have been identified, given names, cataloged and documented in catalogs or books. These patterns are available for off-the-shelf use, just as classes are available in class libraries. Software engineering patterns are patterns on a larger scale than the simple program seen above. The established patterns specify the structure of useful software at the architectural level. In object-oriented development, this means structures expressed in terms of classes and their interrelationships. The strength of design patterns is that good design ideas are recorded, given a name, and explained with the aid of examples. This extends the vocabulary of software developers. It also extends the repertoire of ideas that they can use without reinventing the wheel. To make use of patterns, the software engineer needs some recollection of the standard patterns. This is obtained by browsing a patterns catalog prior to a project. The engineer thereby retains some memory (perhaps only a partial recollection) of the patterns, then, during the early phase of software architectural design, the engineer realizes that one or more patterns may be useful. They then consult the catalog to confirm the appropriateness of the pattern and see exactly how to use it. The next step is to use the pattern as part of the design. In summary the stages are: 1. browse a design pattern catalog, to obtain some feel for the available patterns 2. embark on a new design with an awareness of the patterns 3. recognize the need for one of the established patterns 4. consult the catalog to check the applicability of the pattern 5. use the catalog for information on the how to use the pattern 6. use the pattern as part of the design. As well as architectural structure, patterns are available for such domains as user interfaces, file systems and multithreading. Patterns are also provided for activities such as testing and project management. In order to use design patterns the programmer needs considerable experience and understanding of OOD and OOP. Just as there are patterns (which are valuable structures) so there are anti-patterns, which are undesirable structures. The reason for identifying and cataloguing anti-patterns is to avoid them. We look at one such pattern. In this chapter we present a number of useful patterns and use the cyberspace invaders game as an example in explaining some of the patterns. 12.2 ● Inheritance It bears repeating that one of the major goals of the object-oriented paradigm is to produce reusable software components – components which can be reused both within the application in which they were generated but also in future applications.

CHAPTER<br />

12<br />

This chapter explains:<br />

12.1 ● Introduction<br />

Experienced programmers draw on half-remembered memories of software structures<br />

that they have used themselves or seen used in the past. An example of a simple programming<br />

pattern is the design of a program to find the largest number in an array of<br />

numbers. The simplest algorithm uses a variable to record the largest value that has yet<br />

been encountered. The program starts at the beginning of the array and proceeds item<br />

by item, examining each number, updating this variable as necessary:<br />

largest = list[0]<br />

index = 0<br />

while index largest then<br />

largest = list[index]<br />

end if<br />

index = index + 1<br />

end while<br />

Design patterns<br />

■ how to use design patterns during development<br />

■ several major design patterns<br />

■ some valuable anti-patterns.<br />

This is clearly a small piece of program that is easily constructed by any experienced<br />

programmer, but to novice programmers, seeing this is something of a revelation. And<br />

once seen, the programmer never <strong>for</strong>gets it. Or at least the programmer remembers<br />

the idea of what is needed, rather than the detail. This is a software pattern. Over a<br />

>

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

Saved successfully!

Ooh no, something went wrong!