2.1. Layered Software ArchitectureA good web application should look like a trifle, shown in Figure 2-1. Figure 2-1. A well-layered trifle (photo by minky sue: http://flickr.com/photos/kukeit/8295137)Bear with me here, because it gets worse before it gets better. It's important to note that I mean English trifle and not Canadianthere is only one layer of each kind. This will become clear shortly. If you have no idea what trifle is, then this will still make sensejust remember it's a dessert with layers. At the bottom of our trifle, we have the solid layer of sponge. Everything else sits on top of the sponge. It wouldn't be trifle without it. The sponge supports everything above it and forms the real inner core of the dessert. The sponge is big, solid, and reliable. Everything above it is transient and whimsical. In web applications, persistent storage is the sponge. The storage might be manifested as files on disk or records in a database, but it represents our most important assetdata. Before we can access, manipulate, or display our data, it has to have a place to reside. The data we store underpins the rest of the application. Sitting on top of the sponge is the all-important layer of jelly (Jell-O, to our North American readers). While every trifle has the same layer of spongean important foundation but essentially the same thing everywherethe personality of the trifle is defined by the jelly. Users/diners only interact/eat the sponge with the jelly. The jelly is the main distinguishing feature of our trifle's uniqueness and our sole access to the supporting sponge below. Together with the sponge, the jelly defines all that the trifle really is. Anything we add on top is about interaction and appearance. In a web application, the jelly is represented by our business logic. So we have our supporting sponge and our personality jelly (perhaps with lumps of fruit, which have no sensible analogous component, but are useful ingredients in a trifle, nonetheless). We might have a dessert and we can certainly see the shape it's taking, but it's not yet a trifle. What we need now is custard. Custard covers the jelly and acts as the diners' interface to the layers beyond. The custard doesn't underpin the system; in fact, it can be swapped out when needed. True storyI once burnt custard horribly (burnt milk is really disgusting) but didn't realize how vile it was until I'd poured it over the jelly. Big mistake. But I was able to scrape if off and remake it, and the trifle was a success. It's essentially swappable. In our web application, the custard represents ourpage and interaction logic. The keen observer and/or chef will notice that we don't yet have a full dessert. There's at least one more layer to go, andtwo in our analogy. On top of the custard comes the cream. You can't really have custard without cream; the two just belongtogether on a trifle. A trifle with just custard would be inaccessible to the casual diner. While the hardened chef/developer would recognize a trifle without cream, it just looks like a mess to the diner/user. We need some way to convey the message of the lower layers to our diners/users. In our web application, the part of the cream is played by markup on the Web, GUI toolkits on the desktop, and XML in our APIs. The markup layer There's once thing left to make our trifle complete, other than the crockery (marketing) and diners (users). It would already work as is, containing all the needed parts. A developer might be happy enough to stop here, but the casual user cares more about presentation than perhaps he should. So on the top of our layered masterpiece goes garnish in the form of fruit, sprinkles, or whatever else takes your fancy. The one role this garnish performs, important as it is, is to make the lower layers look nice. Looking nice helps people understand the trifle and makes them more likely to want to eat some (assuming the garnish is well presentedit can also have the opposite effect). Atop the masterpiece of code and engineering comes our metaphorical garnishpresentation. When talking about web pages, presentation is the domain of some parts of the markup, So the point of all this? A good web application has many layers, each of which provides a discrete function. All of the layers together make up the application, but randomly combining them will get you a badly built application or a bowl of sugary foodstuffs. From the perspective of the developer/chef, the most important layers are at the bottom because they support and provide the basis for the ones above. From the perspective of the diner/user, the higher layers are the important part that set the dessert apart, with the lower layers being taken for granted, particularly the ones at the very bottom of the stack. And so it should be with web applications. In a moment, we'll look at how these layers can interact (we can't just rely on gravity, unfortunately; besides, we need a trifle that can withstand being tipped over), but first we'll look at some examples of what can go where. |
Friday, December 18, 2009
Section 2.1. Layered Software Architecture
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment