php objects patterns and practice 3rd edition phần 10

Ngoài ra mặc định cho các gói megaquiz tôi định nghĩa là một bộ chuyển mạch dòng lệnh, bây giờ tôi có thể bấm vào lệnh hoặc quiztools. Bởi vì tôi hiện đang kiểm tra các lớp học trong gói lệnh, các liên kết hình thành các danh sách bên tay trái chuyển hướng chỉ có những lớp học. Nói chung, gói trong | CHAPTER 20 OBJECTS PATTERNS PRACTICE When I first started working with patterns I found myself creating Abstract Factories all over my code. I needed to generate objects and Abstract Factory certainly helped me to do that. In fact though I was thinking lazily and making unnecessary work for myself. The sets of objects I needed to produce were indeed related but they did not yet have alternative implementations. The classic Abstract Factory pattern is ideal for situations in which you have alternative sets of objects to generate according to circumstance. To make Abstract Factory work you need to create factory classes for each type of object and a class to serve up the factory class. It s exhausting just describing the process. My code would have been much cleaner had I created a basic factory class only refactoring to implement Abstract Factory if I found myself needing to generate a parallel set of objects. The fact that you are using patterns does not guarantee good design. When developing it is a good idea to bear in mind two expressions of the same principle KISS Keep it simple stupid and Do the simplest thing that works. eXtreme programmers also give us another related acronym YAGNI. You aren t going to need it meaning that you should not implement a feature unless it is truly required. With the warnings out of the way I can resume my tone of breathless enthusiasm. As I laid out in Chapter 9 patterns tend to embody a set of principles that can be generalized and applied to all code. Favor Composition over Inheritance Inheritance relationships are powerful. We use inheritance to support runtime class switching polymorphism which lies at the heart of many of the patterns and techniques I explored in this book. By relying on solely on inheritance in design though you can produce inflexible structures that are prone to duplication. Avoid Tight Coupling I have already talked about this issue in this chapter but it is worth mentioning here for the sake of .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.