PHP 5/MySQL Programming- P57

PHP 5/MySQL Programming- P57:computer programming has often been seen as a difficult and arcane skill. Programming languages are difficult and complicated, out of the typical person’s reach. However, the advent of the World Wide Web has changed that to some extent. It’s reasonably easy to build and post a Web page for the entire world to see. The language of the Web is reasonably simple, and numerous applications are available to assist in the preparation of static pages | 258 PHP 5 MySQL Programming for the Absolute Beginner change in the Critter class definition Notice that the constructor no longer sets the name property directly but uses the setName method instead. This is useful in a moment. The program adds some new features to the basic Critter class doctype html public - W3C DTD HTML EN html head title Glitter Critter title head body Incorporating Inheritance pull up the Critter class include create new Glitter Critter based on Critter class GlitterCritter extends Critter add one method function glow print this- name . gently shimmers. br n end glow override the setName method function setName newName this- name Glittery . newName end setName end GC class def make an instance of the new critter theCritter new GlitterCritter Gloria GC has no constructor so it borrows from its parent print Critter name . theCritter- getName . br n 259 invoke new glow method theCritter- glow body html The program begins by including the previously designed Critter class. I could now make instances of that class but I have something sneakier in mind. I want to make a new type of Critter that knows how to glow. I ll call it the GlitterCritter. I also wrote prototypes for the HitterCritter BitterCritter and SpitterCritter but I decided not to include them in the book. I defined the GlitterCritter just like any other class except for the extends keyword class GlitterCritter extends Critter Unless I indicate otherwise the GlitterCritter will act just like an ordinary Critter. It automatically inherits all properties methods and even the constructor from the parent class. I added two methods to the class. One brand new method is called glow .The original Critter class doesn t have a glow method. The other method is called setName . The original Critter class has a setName method as well. When you run the program you see a page like Figure . figure The Glitter Critter has some new tricks and borrows others from the

Không thể tạo bản xem trước, hãy bấm tải xuố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.