Demo Example of OPP implementation of three-layer architecture

Source: Internet
Author: User

Example: Demo member Add and delete

Note: Because it is a simple example, we use the screen to print the words "Add success" and "delete success" to indicate the addition and deletion of members , just to demonstrate how to achieve a three-layer separation:

1 if you simply print "Add success" and "delete success" on the screen, it's easy to create a new manage.php directly inside the code below to achieve the effect: There is only one layer, that is, the expression layer , then how to separate it

<?  Echo ' add success '; Echo ' Delete succeeded ';? >

2 new Manage.class.php file, as the data layer,manage.php only need to introduce Manage.class.php and instantiate an object, there are two layers

Manage.class.php (Ignoring the constructor method, which is the third step of the connection)

<?PHPclassmanage{ Public function__construct () {NewManageaction ($this); }        //New Admin         Public functionAddmanage () {returnNew; }         Public functionDeletemanage () {returnDelete; }    }?>

manage.php instead:

<? PHP     // entity class    require ' Manage.class.php ';     // entrance    $_m New Manage ();     Echo $_m, Addmanage ();     Echo $_m, Deletemanage ();? >

3 Business Logic Layer, new ManageAction.class.php file

<? PHP     class manageaction{        publicfunction __construct ($_m) {            Echo  $_m, Addmanage ();             Echo $_m-Deletemanage ();        }    ? >

manage.php instead: three-layer separation is achieved.

<? PHP     // entity class    require ' Manage.class.php ';     // Business Controller    require ' ManageAction.class.php ';     // entrance    $_m New Manage ();? >

Also: Action.class.php and Model.class.php are base classes for handling redundant three-layer what

See the source file for examples

Demo Example of OPP implementation of three-layer architecture

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.