TAILIEUCHUNG - PHP Objects, Patterns, and Practice- P2

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 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

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.