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.