As you'll possibly recall from the previous section, I said that I was going to derive a child class from the prior parent "WebPage" to implement all of its abstract methods, and in consequence, define a class capable of displaying a basic web document. Based on this premise, below I included the signature of a brand new class, called "HomeWebPage." As its name suggests, it is responsible for creating the front page of a fictional web site. The definition for this class is as follows: // define concrete 'HomeWebPage' class <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> EOD; h2{ p{ #header{ #navbar{ #navbar ul{ #navbar li{ #navbar a:link,#navbar a:visited{ #navbar a:hover{ #mainwrapper{ #mainwrapper .leftcol{ #mainwrapper .rightcol{ #leftbar{ #centerbar{ #rightbar{ #footer{ EOD; <title>$this->title</title> EOD; <div id="mainwrapper"> EOD; <div id="footer"> EOD; As you can see, the above "HomeWebPage" class is merely a child of the corresponding parent defined in the previous section, and implements all of its prior abstract methods to build the home page of a sample web site. Of course, in this case the aforementioned "HomeWebPage" class uses a part of its logic to display the different sections of a basic web page, which implies that it deals at a certain level with the visual presentation of the web site in question. But, as you know, this isn't a good practice in general terms, so this issue could be fixed easily by using a template instead of including hard-coded structural markup within some class methods. However, in this case I'm going to keep the definition of the previous "HomeWebPage" class untouched, so you can see more clearly how an inherited class can be used to build a simple web page. All right, having clarified this important point, it's time to recapitulate what I have done so far. At this point I derived a child class from the corresponding parent, which comes in handy for displaying the home web page of a fictional site, a process that uses the principle of inheritance. Nevertheless, I'd like to go one step further and show you how to utilize the same concept, but this time to create another web document of the sample web site in question. Maybe you think that this could be quickly achieved by deriving another subclass from the respective parent, and you'd be right. But, in this case there's a much better approach to follow. Since the initial "HomeWebPage" class already encapsulates all the logic required to display a web page, it'd be much easier to derive a child from it, and eventually override/overload some of its methods. Now, are you starting to realize how inheritance can be used in a simple fashion to build a complete web site? I bet you are! So, now that I have generally outlined how a different web page of this fictional web site can be quickly built by using the functionality provided by inheritance, please jump into the next section and keep reading to learn how this process will be performed.
blog comments powered by Disqus |
|
|
|
|
|
|
|