TAILIEUCHUNG - OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P12

OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P12:A number of years ago, before I started using PHP, I created dynamic web pages using C. This really wasn’t too different from some of the other options available at the time, though it seems almost unthinkable now. Creating a dynamic page meant outputting HTML from your script and recompiling that script if any changes needed to be made. | 11 ADVANCED OBJECT-ORIENTED programming concepts The previous two chapters introduced a number of new object-oriented programming OOP concepts. In the interest of clarity some topics were discussed in depth and others glossed over. While the content of those chapters is still fresh in your mind let s return to some of the topics that were only touched upon briefly namely abstract classes the use of the static keyword and the implications of type hinting. Abstract Classes In Chapter 10 we saw that if a derived class does not implement all the methods of an interface then it must be declared abstract. Let s push this concept to the extreme and see what a completely abstract class might look like. Listing 11-1 shows the definition of such a class. abstract class Bird protected plumage protected migratory abstract public function abstract public function abstract public function abstract public function abstract public function abstract public function abstract public function abstract public function __construct fiy sing eat0 setPlumage plumage getPlumage setMigratory migratory getMigratory Listing 11-1 The definition of the abstract class Bird As we saw in Chapter 10 any class that contains abstract methods must include O the keyword abstract in its class declaration. That class may have any number of data members and any number of methods with or without an implementation. However if a method lacks an implementation it must also be declared abstract. The class in Listing 11-1 has data members declared as protected making them available to derived classes. This class could be termed a pure abstract class because all of its methods are abstract. Note that all the methods of this class are declared public. Let s see why that is so. Private Methods Can t Be Abstract Methods identified as abstract cannot be private they must be either public or protected. The reason is that an abstract private method is a contradiction in terms. Because an abstract class has undefined .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
TÀI LIỆU XEM NHIỀU
5    3    0
17    4    0
TÀI LIỆU HOT
202    9    0
TÀI LIỆU LIÊN QUAN
6    9    0