21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

160 Chapter 12 ■ Design patterns<br />

Figure 12.5 Layers<br />

user interface layer<br />

business logic layer<br />

database access layer<br />

database level stores and retrieves documents. The middle layer processes commands,<br />

such as deleting text.<br />

The strength of the Layers pattern is that it provides a large-scale structure <strong>for</strong> certain<br />

types of software. It also means that each layer of the software can be modified<br />

without affecting the other layers. For example, in the word processor, we can alter the<br />

way that commands are invoked (the presentation layer), <strong>for</strong> example, by adding<br />

menus, without changing the database access layer.<br />

The word processor is a single-machine application. However, many current<br />

applications – such as an ATM – are network-based or internet-based. The simplest<br />

network-based architecture is the client-server architecture. This consists of two layers –<br />

the client software running on the client machine and the server software running on the<br />

server. The classic example is a web browser and a web server. The client passes a request<br />

to the server; the server responds.<br />

A classic example of the Layers pattern is the structure of the software <strong>for</strong> internet<br />

communication, called the TCP/IP stack. Every computer that uses the internet has<br />

this software. A typical application program makes requests on the transport layer that<br />

supports the TCP protocol. This in turn makes requests of the internet layer that supports<br />

the IP protocol. This in turn calls the physical layer which actually carries out<br />

data transfers. Thus the software consists of four levels, including the application level.<br />

Another version of the Layers pattern, with four levels, describes many networked<br />

solutions, Figure 12.6. Again, each layer uses the layer below it. The communication<br />

between presentation and server layer is carried out according to a chosen network protocol,<br />

such as HTTP.<br />

In designing a distributed system, there are choices about which layer does what. In<br />

a thin client system, the client software does very little, while the bulk of the work is<br />

carried out on the server. In a fat client architecture, the business logic layer migrates<br />

to the client machine. The decision about where to per<strong>for</strong>m processing depends on<br />

such issues as per<strong>for</strong>mance, maintenance and security.<br />

Another benefit of the Layers pattern is facilitating security. The boundaries between<br />

layers serve as well-defined interfaces where security checks can be carried out. For<br />

example encryption can be used between the client and the server. Finally, Layers provide<br />

<strong>for</strong> scalability. A server acting as a proxy (see pattern above) can delegate its task<br />

to other servers as the load increases.

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

Saved successfully!

Ooh no, something went wrong!