TAILIEUCHUNG - PHP Objects, Patterns, and Practice- P5

PHP Objects, Patterns, and Practice- P5: This book takes you beyond the PHP basics to the enterprise development practices used by professional programmers. Updated for PHP with new sections on closures, namespaces, and continuous integration, this edition will teach you about object features such as abstract classes, reflection, interfaces, and error handling. You’ll also discover object tools to help you learn more about your classes, objects, and methods. | CHAPTER 10 PATTERNS FOR FLEXIBLE OBJECT PROGRAMMING and queries transparent to the client. Trees are easy to traverse as we shall see in the next chapter . It is easy to add new component types to Composite structures. On the downside Composites rely on the similarity of their parts. As soon as we introduce complex rules as to which composite object can hold which set of components our code can become hard to manage. Composites do not lend themselves well to storage in relational databases but are well suited to XML persistence. The Decorator Pattern While the Composite pattern helps us to create a flexible representation of aggregated components the Decorator pattern uses a similar structure to help us to modify the functionality of concrete components. Once again the key to this pattern lies in the importance of composition at runtime. Inheritance is a neat way of building on characteristics laid down by a parent class. This neatness can lead you to hard-code variation into your inheritance hierarchies often causing inflexibility. The Problem Building all your functionality into an inheritance structure can result in an explosion of classes in a system. Even worse as you try to apply similar modifications to different branches of your inheritance tree you are likely to see duplication emerge. Let s return to our game. Here I define a Tile class and a derived type abstract class Tile abstract function getWealthFactor class Plains extends Tile private wealthfactor 2 function getWealthFactor return this- wealthfactor I define a Tile class. This represents a square on which my units might be found. Each tile has certain characteristics. In this example I have defined a getWealthFactor method that affects the revenue a particular square might generate if owned by a player. As you can see Plains objects have a wealth factor of 2. Obviously tiles manage other data. They might also hold a reference to image information so that the board could be drawn. Once again I ll .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.