PHP design mode singleton mode single case mode and multi-instance mode Java single-case design mode enjoy meta-mode singleton model

Source: Internet
Author: User
What is a single case, and what is its role?

The singleton pattern is understood from the name. Single is once. The example is to instantiate an object, that is, I don't care how many times I use it to instantiate an object. OK, what is the function of this design pattern?

The singleton mode can ensure that there is only one instance of a class in the system, and the instance is easy to be accessed by the outside world, thus it is convenient to control the number of instances and save system resources.

For example, we're going to write a class that operates on MySQL. Connect to the database operation in the construction method. This class is used every new time if it is the usual notation. We've created a database connection here. For example, I have 100 files on my side that are called to this class at the same time. Every time you declare this MySQL class, you have to connect to the database. It's a pretty big expense. In order to solve this problem. A singleton pattern was born.


Singleton mode ">

The above introduces the PHP design mode singleton mode, including the design mode, the content of the singleton mode, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.