Danh mục

Developing Large Web Applications- P4

Số trang: 10      Loại file: pdf      Dung lượng: 284.39 KB      Lượt xem: 16      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: 1,000 VND Tải xuống file đầy đủ (10 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Developing Large Web Applications- P4:This book presents a number of techniques for applying established practices of goodsoftware engineering to web development—that is, development primarily using thedisparate technologies of HTML, CSS, JavaScript, and server-side scripting languages.Whereas there are many books on how to use languages, how to use libraries, and howto approach software engineering, this is the first book to codify many of the techniquesit presents. These techniques will make the components of your own web applicationsmore reusable, maintainable, and reliable....
Nội dung trích xuất từ tài liệu:
Developing Large Web Applications- P4Figure 2-2. Classes related by associationModeling a Web PageNow let’s turn to the class diagram for a web page, shown in Figure 2-3. This diagramcaptures the way we’re going to think about web pages when we write some PHP codeto build them in a modular fashion in Chapter 7. It doesn’t capture all the details ofthe implementation in Chapter 7, but it shows enough to illustrate the resemblancebetween this type of model and its object-oriented code in Example 2-3. Our diagramhas two fundamental entities: pages and modules.Defining Page TypesThe most general form of a page is represented by a class called Page, which representsthe data and operations for web pages across all types of web applications. We alsorecognize the need for more specialized classes of pages on a specific website (e.g.,SitePage), pages on certain sections of the site (e.g., NewCarsPage), and pages for veryspecific purposes (e.g., NewCarSearchResultsPage). The diagram further conveys thefundamental use of modules in pages. Every page is composed of modules, and a mod-ule conversely has an association with the page on which it resides. This way, it canadd what it needs to the page.To keep things simple for now, the diagram shows just one data member for Page,js_module, and one operation, add_to_js. In Chapter 7, you’ll see that modules need away to add their JavaScript to a page, and add_to_js provides a way to do this. Pagesneed someplace to collect the JavaScript, and the diagram shows the data memberjs_module for just this purpose.Defining Module TypesThe most general class of module is Module, which represents the data and operationscommon to all modules. We also recognize the need for more specialized classes ofmodules to implement modules for very specific purposes (e.g., NavBar), as well aslayouts and containers, which are themselves more specific forms of Layout. Modeling a Web Page | 11Figure 2-3. A class diagram for modeling a web pageWriting the CodeOnce we have this model for a web page, it’s relatively easy to use object orientationto write the code that represents it, as shown in Example 2-3. Again, we’ll fill in thedetails for some of these classes in Chapter 7. For now, the important point to recognizeis how closely the object-oriented code of Example 2-3 corresponds to the class diagramfrom Figure 2-3. That is, object-oriented programming has narrowed the gap betweenour thought process and the computer model.Example 2-3. PHP from the class diagram// These are the base classes for all pages, modules, and layouts.class Page{ protected $js_module; ... protected $modules; ...12 | Chapter 2: Object Orientation public function add_to_js($js) { ... } ...}class Module{ protected $page ...}class Layout extends Module{ protected $modules; ...}// The following class supports capabilities across an entire site.class SitePage extends Page{ ...}// Page classes like this add capabilities across specific sections.class NewCarsPage extends SitePage{ ...}// Page classes like this support capabilities for specific pages.class NewCarSearchResultsPage extends NewCarsPage{ ...}// Module classes like this add capabilities for specific modules.class NavBar extends Module{ ...}// Layout and container classes are reusable groupings for modules.class ResultsLayout extends Layout{ ...}class Container2x1Mid extends Layout{ ...} Writing the Code | 13Achieving ModularityAnother important aspect of object orientation is how well it facilitates modularity,which is essential to improving reusability, maintainability, and reliability over the lifeof a large web application. To achieve modularity, we need to build large applicationsfrom components that are cohesive (i.e., neatly encapsulated and abstracted) and looselycoupled.Objects in object-oriented systems are naturally cohesive because their data and meth-ods are grouped into nicely encapsulated bundles by virtue of being defined within aclass (or in object-based languages, added to an object). Furthermore, you can abstractthe implementation details for an object by hiding its data members and certain meth-ods with private or protected visibility (see “Classes and Interfaces” on page 15). Asa result, the data and methods tend to stick together.Objects are loosely coupled when they aren’t overly dependent on one another andthey interact in clearly defined ways. The public and protected methods of an objectestablish a clear interface for how others may interact with it. You can see the depend-encies among objects by visualizing a class diagram as a dependency graph. A depend-ency exists wherever there is a generalization ...

Tài liệu được xem nhiều: