PHP and MySQL Web Development - P37

PHP and MySQL Web Development - P37: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Creating Classes Attributes Operations in PHP 147 Polymorphism An object-oriented programming language must support polymorphism which means that different classes can have different behaviors for the same operation. If for instance we have a class car and a class bicycle both can have different move operations. For real-world objects this would rarely be a problem. Bicycles are not likely to get confused and start using a car s move operation instead. However a programming language does not possess the common sense of the real world so the language must support polymorphism in order to know which move operation to use on a particular object. Polymorphism is more a characteristic of behaviors than it is of objects. In PHP only member functions of a class can be polymorphic. A real world comparison is that of verbs in natural languages which are equivalent to member functions. Consider the ways a bicycle can be used in real can clean it move it disassemble it repair it or paint it among other things. These verbs describe generic actions because you don t know what kind of object is being acted on. This type of abstraction of objects and actions is one of the distinguishing characteristics of human intelligence. For example moving a bicycle requires completely different actions from those required for moving a car even though the concepts are similar. The verb move can be associated with a particular set of actions only once the object acted on is made known. Inheritance Inheritance allows us to create a hierarchical relationship between classes using subclass inherits attributes and operations from its superclass. For example car and bicycle have some things in common. We could use a class vehicle to contain the things such as a color attribute and a move operation that all vehicles have and then let our car and bicycle classes inherit from vehicle. With inheritance you can build on and add to existing classes. From a simple base class you can

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
32    71    2    29-03-2024
Đã 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.