Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
PHP Objects, Patterns, and Practice- P2: This book takes you beyond the PHP basics to the enterprise development practices used by professional programmers. Updated for PHP 5.3 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 3 OBJECT BASICS function getSummaryLine base this- title this- producerMainName base . this- producerFirstName if this- type book base . page count - this- numPages else if this- type cd base . playing time - this- playLength return base In order to set the type property I could test the numPages argument to the constructor. Still once again the ShopProduct class has become more complex than necessary. As I add more differences to my formats or add new formats these functional differences will become even harder to manage. Perhaps I should try another approach to this problem. Since ShopProduct is beginning to feel like two classes in one I could accept this and create two types rather than one. Here s how I might do it class CdProduct public playLength public title public producerMainName public producerFirstName public price function construct title firstName mainName price playLength this- title title this- producerFirstName firstName this- producerMainName mainName this- price price this- playLength playLength function getPlayLength return this- playLength function getSummaryLine base this- title this- producerMainName base . this- producerFirstName base . playing time - this- playLength return base function getProducer return this- producerFirstName . this- producerMainName class BookProduct 29 CHAPTER 3 OBJECT BASICS public numPages public title public producerMainName public producerFirstName public price function construct title firstName mainName price numPages this- title title this- producerFirstName firstName this- producerMainName mainName this- price price this- numPages numPages function getNumberOfPages return this- numPages function getSummaryLine base this- title this- producerMainName base . this- producerFirstName base . page count - this- numPages return base function getProducer return this- producerFirstName . this- producerMainName I have addressed the complexity issue but at a cost. I can now create a getSummaryLine method for