When multiple Model subclasses are called in phpController, the parent class of the Model is instantiated multiple times.

Source: Internet
Author: User
Each Model subclass inherits the same parent class, for example, classModel_UserextendsModel {} ClassModel_ArticleextendsModel {} Model parent class encapsulates data sources, caches, and other common data operation methods. The problem is that each Model subclass in Co... inherits the same parent class, for example:

Class Model_User extends Model {

}

Class Model_Article extends Model {

}

The Model parent class encapsulates data sources, caches, and other common data operations.

The problem is that when the Controller calls both Model_User and Model_Article, isn't the Model parent class be instantiated twice?

After reading other frameworks, some define the $ _ table and $ _ pk attributes in the Model parent class, and $ _ db_connection is used as a singleton, subclass must specify its own $ _ table and $ _ pk, but some other methods encapsulated in the parent class will also be instantiated multiple times by "meaningless.

What do you think of this question?

Reply content:

Each Model subclass inherits the same parent class, for example:

Class Model_User extends Model {

}

Class Model_Article extends Model {

}

The Model parent class encapsulates data sources, caches, and other common data operations.

The problem is that when the Controller calls both Model_User and Model_Article, isn't the Model parent class be instantiated twice?

After reading other frameworks, some define the $ _ table and $ _ pk attributes in the Model parent class, and $ _ db_connection is used as a singleton, subclass must specify its own $ _ table and $ _ pk, but some other methods encapsulated in the parent class will also be instantiated multiple times by "meaningless.

What do you think of this question?

You don't seem to understand the meaning of inheritance.

You have inherited some genes from your father. No matter how much your genes change, it will not directly affect your father, nor affect your brother.
Although it is inherited, it is yours and has nothing to do with your father.

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.