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 12.4 Pipe and Filter pattern 12.12 Layers 159 known as a filter and the connections are known as pipes. The information flow between components is a one-way serial stream of data. Each component knows nothing about any other component. This scheme corresponds to the pipe and filter scheme that Unix provides. Many of the Unix utility programs process a stream of data and create a new output stream. Examples are given in Chapter 18 on scripting languages. Arguably, this type of connection means that the components have minimal coupling. 12.11 ● Proxy Filter 1 Filter 2 Filter 3 A proxy object acts instead of some other object or objects. It fields requests, passing them on as necessary. The classic example is that of a proxy server on the internet, which acts in place of another server because the actual server is too busy. The proxy either handles requests itself or passes a request on to an available server. A busy website, such as a successful search engine, cannot handle all the requests using a single server. Instead it uses a collection of servers, fronted by a proxy server that farms out the work to an available server. SELF-TEST QUESTION 12.4 Compare and contrast the Proxy pattern with the Façade pattern. 12.12 ● Layers The Layers pattern, sometimes called tiers, is a classic pattern that is used in many systems. This pattern divides a software system into hierarchical layers. In one incarnation, Figure 12.5, there are three layers. The top layer handles the user interface (sometimes called the presentation layer), the middle layer handles the application logic (sometimes called the domain logic or the business logic) and the bottom layer handles access to the database. Each layer makes requests on the services provided by the layer immediately below it, and receives replies, but there are no other dependencies in this structure. The layers pattern can be used to structure the word processor (Appendix A). The user interface provides the display of the current document and a set of commands. The

160 Chapter 12 ■ Design patterns Figure 12.5 Layers user interface layer business logic layer database access layer database level stores and retrieves documents. The middle layer processes commands, such as deleting text. The strength of the Layers pattern is that it provides a large-scale structure for certain types of software. It also means that each layer of the software can be modified without affecting the other layers. For example, in the word processor, we can alter the way that commands are invoked (the presentation layer), for example, by adding menus, without changing the database access layer. The word processor is a single-machine application. However, many current applications – such as an ATM – are network-based or internet-based. The simplest network-based architecture is the client-server architecture. This consists of two layers – the client software running on the client machine and the server software running on the server. The classic example is a web browser and a web server. The client passes a request to the server; the server responds. A classic example of the Layers pattern is the structure of the software for internet communication, called the TCP/IP stack. Every computer that uses the internet has this software. A typical application program makes requests on the transport layer that supports the TCP protocol. This in turn makes requests of the internet layer that supports the IP protocol. This in turn calls the physical layer which actually carries out data transfers. Thus the software consists of four levels, including the application level. Another version of the Layers pattern, with four levels, describes many networked solutions, Figure 12.6. Again, each layer uses the layer below it. The communication between presentation and server layer is carried out according to a chosen network protocol, such as HTTP. In designing a distributed system, there are choices about which layer does what. In a thin client system, the client software does very little, while the bulk of the work is carried out on the server. In a fat client architecture, the business logic layer migrates to the client machine. The decision about where to perform processing depends on such issues as performance, maintenance and security. Another benefit of the Layers pattern is facilitating security. The boundaries between layers serve as well-defined interfaces where security checks can be carried out. For example encryption can be used between the client and the server. Finally, Layers provide for scalability. A server acting as a proxy (see pattern above) can delegate its task to other servers as the load increases.

Figure 12.4 Pipe and Filter pattern<br />

12.12 Layers 159<br />

known as a filter and the connections are known as pipes. The in<strong>for</strong>mation flow<br />

between components is a one-way serial stream of data. Each component knows<br />

nothing about any other component. This scheme corresponds to the pipe and filter<br />

scheme that Unix provides. Many of the Unix utility programs process a stream of<br />

data and create a new output stream. Examples are given in Chapter 18 on scripting<br />

languages. Arguably, this type of connection means that the components have minimal<br />

coupling.<br />

12.11 ● Proxy<br />

Filter 1 Filter 2 Filter 3<br />

A proxy object acts instead of some other object or objects. It fields requests, passing<br />

them on as necessary.<br />

The classic example is that of a proxy server on the internet, which acts in place of<br />

another server because the actual server is too busy. The proxy either handles requests<br />

itself or passes a request on to an available server. A busy website, such as a successful<br />

search engine, cannot handle all the requests using a single server. Instead it uses<br />

a collection of servers, fronted by a proxy server that farms out the work to an available<br />

server.<br />

SELF-TEST QUESTION<br />

12.4 Compare and contrast the Proxy pattern with the Façade pattern.<br />

12.12 ● Layers<br />

The Layers pattern, sometimes called tiers, is a classic pattern that is used in many<br />

systems. This pattern divides a software system into hierarchical layers. In one incarnation,<br />

Figure 12.5, there are three layers. The top layer handles the user interface<br />

(sometimes called the presentation layer), the middle layer handles the application<br />

logic (sometimes called the domain logic or the business logic) and the bottom layer<br />

handles access to the database. Each layer makes requests on the services provided<br />

by the layer immediately below it, and receives replies, but there are no other<br />

dependencies in this structure.<br />

The layers pattern can be used to structure the word processor (Appendix A). The<br />

user interface provides the display of the current document and a set of commands. The

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

Saved successfully!

Ooh no, something went wrong!