PHP miscellaneous Reconstruction

Source: Internet
Author: User
Motivation: indirect access variable: supports more flexible data acquisition methods, such as lazyInitialization (meaning Initialization is performed only when a value is used .) Directly access the variable: the code is easier to read and does not need to be stopped. Ah, this is just a value function. Choice: 1. Code specification, according to the practices of most people in the team. 2. Individual

Motivation: indirect access to variables: supports more flexible data acquisition methods, such as lazy Initialization (meaning Initialization is performed only when a value is used .) Directly access the variable: the code is easier to read and does not need to be stopped. Ah, this is just a value function. Choice: 1. Code specification, according to the practices of most people in the team. 2. Individual

Motivation:

"Indirect access variable": supports more flexible data acquisition methods, such as lazy Initialization (meaning it is initialized only when a value is used .)

"Direct access to variables": the code is easier to read and does not need to be stopped. "Ah, this is just a value function ".

Choice: 1. Code specification, according to the practices of most people in the team.

2. individuals prefer "directly accessing variables" until this method brings trouble.

Example of martin (author): If you want to obtain the field in superclass, but want to change the field to the calculated value in subclass, Self Encapsulate Field should be used most.

My own example: I usually set the field to private. If the external variable needs to use this field, I will use Self Encapsulate Field. Or when the field value changes, use Self Encapsulate Field.


Replace Data Value with Object

Condition: If you need additional data and behavior for a basic field type, convert the field to an object.

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.