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.