TAILIEUCHUNG - php objects patterns and practice 3rd edition phần 4

Để xử lý mã cơ sở dữ liệu linh hoạt, bạn nên tách riêng các ứng dụng logic từ các chi tiết cụ thể của nền tảng cơ sở dữ liệu nó sử dụng. Bạn sẽ thấy rất nhiều cơ hội cho loại tách thành phần của các thành phần trong các dự án của riêng bạn. | CHAPTER 8 SOME PATTERN PRINCIPLES Loosening Your Coupling To handle database code flexibly you should decouple the application logic from the specifics of the database platform it uses. You will see lots of opportunities for this kind of component separation of components in your own projects. Imagine for example that the Lesson system must incorporate a registration component to add new lessons to the system. As part of the registration procedure an administrator should be notified when a lesson is added. The system s users can t agree whether this notification should be sent by mail or by text message. In fact they re so argumentative that you suspect they might want to switch to a new mode of communication in the future. What s more they want to be notified of all sorts of things. So that a change to the notification mode in one place will mean a similar alteration in many other places. If you ve hardcoded calls to a Mailer class or a Texter class then your system is tightly coupled to a particular notification mode. Just as it would be tightly coupled to a database platform by the use of a specialized database API. Here is some code that hides the implementation details of a notifier from the system that uses it. class RegistrationMgr function register Lesson lesson do something with this Lesson now tell someone notifier Notifier getNotifier notifier- inform new lesson cost lesson- cost abstract class Notifier static function getNotifier acquire concrete class according to configuration or other logic if rand 1 2 1 return new MailNotifier else 139 CHAPTER 8 SOME PATTERN PRINCIPLES return new TextNotifier abstract function inform message class MailNotifier extends Notifier function inform message print MAIL notification message n class TextNotifier extends Notifier function inform message print TEXT notification message n I create RegistrationMgr a sample client for my Notifier classes. The Notifier class is abstract but it does implement a static method .

TỪ KHÓA LIÊN QUAN
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.