Home  >  Article  >  Backend Development  >  Is it necessary for beginners to always adhere to object-oriented design?

Is it necessary for beginners to always adhere to object-oriented design?

WBOY
WBOYOriginal
2016-12-01 00:01:201108browse

Sometimes it is not possible to properly abstract the desired function into a class, so it can only be implemented process-oriented (there is even no way to integrate it into a function). So how should we do it at this time? Will the habit of "let the code run as expected first, and then refactor it later" have a negative impact in the future?

Reply content:

No, because it is simply impossible to learn it so early. Learn to write code first, and then get object-oriented. Of course, this does not mean that you should not use classes. Anyway, beginners can use them casually. If they use them more, they will have a deeper understanding of best practice in the future. Going to OO in order to solve a problem is correct thinking. Going to OO in order to solve a problem is a disease and cannot be cured. No, first of all not all problems are suitable to be solved by object-oriented, and for beginners, it is more important to consolidate the foundation; if you want to learn object-oriented, you might as well solve the previous exercises in object-oriented way and find out the feeling.


Follow my "Node Flash" Zhihu column and learn a Node/front-end skill in 15 minutes. All source codes are provided. Not everything has to be turned into a class, object-oriented is just one way. If you really want to do oo for the sake of oo, a small program can be written very huge, and it is of no use because there are too many redundant classes and it is still difficult to maintain.

Besides, many times you can only go to the step of "writing it so that the code can run". Refactoring is still far away. Many projects may not even get the chance to refactor. To learn the art of swordsmanship, one needs to observe each school's swordsmanship, move from the complex to the simple, extract the most general principles from them, and form one's own understanding of the swordsmanship.
Then you need to proceed from simple to complex, and arrange and combine the general legal principles to form your own swordsmanship.
The same is true for programming First you have to have a target, and then you can write to her Write more code. When you use frameworks (qt, wpf...) in the future, you can recite incantations, and then learn the encapsulation ideas of these good frameworks. At least you can learn the factory mode.

When I was learning C, I wrote every data structure and every algorithm by myself. Then after I learned C++, Java, and C#, I discovered that these things are readily available and easy to use, and then I naturally learned to be object-oriented. . Process-oriented means process-oriented writing.

After all, you are a beginner and don’t know how to be object-oriented.

This is at least tolerable
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn