Is it necessary to split and encapsulate the php method too long?
Source: Internet
Author: User
Ask if php's method body is too long. is it necessary to split and encapsulate it? if a method body is too long, is it necessary to split several major internal functions and encapsulate calls? the premise is that the encapsulated methods will not be reused, the long problem is that the code is not easy to view, so I may split several functional module files to include. if you call these details elsewhere, it is necessary to split them into other units. this is my personal practice. is it necessary to split and encapsulate the php method too long?
If a method is too long, is it necessary to split several internal functions and encapsulate the call?
The premise is that the encapsulated method will not be reused.
------ Solution --------------------
The long problem is that it is inconvenient to view the code.
So I may split it into several functional module files: include.
If you call these details elsewhere, it is necessary to split them into other units.
This is my personal practice.
------ Solution --------------------
How many functions does one method need to complete? Obviously, it is to be split.
A function is a function. if there are several functions, there should be several functions.
At this point, there is no country difference
------ Solution --------------------
This can also be considered to have little to do with reuse. You divide long functions into several functions. It is easy to read and make it clear to others. In addition, you only need to modify it in a specific part. And mvc.
------ Solution --------------------
The encapsulated structure is clearer. Add comments. So that the maintenance will not be dizzy ..
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.