I had a medium-size task done in procedural style so I thought of converting the code to OOP for ease of maintenance. The original code was a big block in a single file and what I did was:
- Break down the task into functions which handle a part of the task - Put the functions into a class for method chainingAfter conversion, the code become like this:
$obj开发者_高级运维 = new Class();
$result = $obj->task1()->task2()->task3()->task4()->getResult();
I can either leave it like this or further convert each task into a class for more abstraction. What are your takes on refactoring code just for maintainability and readability (and possibly portability once I break down the functions further and convert them into classes) ?
Classes are not bags of functions, and method chainning is not a valid reason for moving to OOP. Read about OOP principles and what it can do better than procedural.
精彩评论