TAILIEUCHUNG - Rails for Java Developers phần 4

Quan điểm chính trong việc thiết kế của Matz là nhằm giảm thiểu các công việc nhàm chán mà họ, các nhà lập trình, buộc phải làm; tiếp đến là nguyên tắc thiết kế giao diện người dùng (user interface) hiệu quả.[3] Ông nhấn mạnh rằng việc thiết kế hệ thống cần phải tập trung vào con người, hơn là vào máy tính | MIXINS 91 def add_employee employee employee if self .employees employee self end def remove_employee employee employee nil end end Classes such as BusinessPerson can then pick up Employer functionality by calling include Employer Download code rails_xt samples class BusinessPerson Person include Employer Employee end Now the BusinessPerson class can call any Employer methods irb main 001 0 require business_person true irb main 002 0 boss Justin Gehtland BusinessPerson 0x54394 @first_name Justin @last_name Gehtland irb main 003 0 drone Stu Halloway BusinessPerson 0x4f9d4 @first_name Stu @last_name Halloway irb main 004 0 drone etc. The fact that include is a method call has interesting implications. The object model is not static and you could choose to have BusinessPerson include Employer under some circumstances and not others. In fact you can make object model decisions per instance instead of per class. The extend method works like include but on a specific instance. So a specific person could become an Employer at runtime irb main 001 0 require business_person true irb main 002 0 p Stu Halloway Person 0x5490c @first_name Stu @last_name Halloway irb main 003 0 class p ancestors end Person Object Kernel irb main 004 0 Employer Person 0x5490c @first_name Stu @last_name Halloway irb main 005 0 class p ancestors end Employer Person Object Kernel The variable p starts life as a plain old Person with class ancestors Person Object Kernel . The extend Employer call turns p into an Employer as well and the ancestor list changes appropriately. The odd-looking Functions 92 statement class p accesses the singleton class of p. A singleton class singleton class might better be known as an instance-specific class. You have modified the inheritance hierarchy of p so it is not

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.