Simple Application of abstract classes

Source: Internet
Author: User
Tags php source code

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.