Đang chuẩn bị liên kết để tải về tài liệu:
Developing Large Web Applications- P29
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Developing Large Web Applications- P29:This book presents a number of techniques for applying established practices of good software engineering to web development—that is, development primarily using the disparate 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 how to approach software engineering, this is the first book to codify many of the techniques it presents. These techniques will make the components of your own web applications more reusable, maintainable, and reliable | Adding Module Variations The more places you use a module within a large web application the more likely you ll need different variations of it. When these variations require coordinated changes to a module s HTML CSS and JavaScript they can become difficult to manage. Fortunately the architecture we ve described for modules makes handling such variations much easier. Because everything a module needs to function correctly is encapsulated inside the module class itself you have a complete picture of what needs to change to support future variations. Often variations will require new parameters to configure the module but you want to avoid altering code where the module is used already. There are a couple of ways to handle this you can define additional parameters for the constructor of the module and adapt the constructor to treat the parameters as optional or you can define setter methods to handle the additional parameters after construction. Let s revisit the Picture Slider module from Chapter 7 to examine how both of these alternatives work. Example 10-11 shows a small part of the implementation provided there. Suppose in a new variation of the module you want to allow the width of the pictures and the number of frames to be configured wherever the module is used. In Chapter 7 these were fixed at 65 and 8 respectively. Example 10-11. The original implementation for the Picture Slider module class PictureSlider extends Module var gallery var type var picture_width var slider_frames public function __construct page gallery parent __construct page this- gallery gallery this- type default this- picture_width 65 this- slider_frames 8 Again the key is that you don t want to alter code at any of the points where the module is already being used. This is how existing instances of the module are created mod new PictureSlider this gallery slider mod- create Example 10-12 shows how you could use optional parameters within the constructor to support the new variation of .