Introduction: This is a detailed page for simple application of abstract classes. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 349768 'rolling = 'no'>
In my blogArticleThe list is consistent with the reading of a single article. In my opinion, except for the SQL query statement structureCodeDifferent. However, these two are the main functions, so this is indeed not suitable, but I did read some design patterns last night, so I have to write something better.
All right: the postparent of the parent class is defined as abstract. It is required that the subclass must implement the buildhtml () method again. This method does not have curly brackets. If there is any content, an error will be reported.
The more I see it, the more I feel that this code does not need to use abstract classes. inheritance is also very rare. Well, there is nothing to say about it .....
In addition, I separated MySQL from the outside, so it is very troublesome to call the method.
1. instantiate readarticle first
2. MySQL query. The parameter is from readarticle: getsql ();
3. Return the MySQL result resource to readarticle: fetchresult ($ result );
4, readarticle: buildhtml (); returns html
If it is a list loop output, you can call 3 and 4 again.
Abstract class postparent
{
Protected $ querysql;
Public $ fetchresult;
Public $ timeago; // eg: 2 days ago
Abstract protected function buildhtml ();
Public Function getsql ()
{
Return $ this-> querysql;
}
Public Function fetchresult ($ result)
{
$ This-> fetchresult = mysql_fetch_assoc ($ result );
}
Public Function error ()
{}
}
Class readarticle extends postparent
{
Public Function _ construct ($ id)
{
$ This-> querysql = <EOF
Select title, author, text, unixtime from post
Where id = $ id order by unixtime DESC;
EOF;
}
Public Function buildhtml ()
{
Return <EOF
<Div id = "post-text">
<Div class = "post-title-Div">
<H4>
<A href = "http://foodstory.me/post.php? Id = {$ this-> fetchresult ['id']}"
Class = "post-title-a" >{$ this-> fetchresult ['title']}
</A>
</H4>
</Div>
<Div class = "post-Info-Div">
<SPAN class = 'post-Info-author' >{$ this-> fetchresult ['author']} </span>
<Time class = 'post-Info-time' >{$ this-> timeago} </time>
</Div>
<Div class = "post-p-Div">
{$ This-> fetchresult ['text']}
</Div>
</Div>
EOF;
}
}
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/349768.html pageno: 3