java - 学习设计模式有利于读懂开源项目的代码吗?
伊谢尔伦
伊谢尔伦 2017-04-17 11:45:48
0
4
513

最近在阅读一些优秀的开源项目源码的时候,遇到了一个问题。

对于某一行代码,我知道它是用来做什么的,但是就是不明白作者为什么要这么写。

我想了一下,觉得可能是自己对于程序设计这一块不熟悉。所以打算从设计模式入手。我的问题是,设计模式能否满足我的需要?还是说我现在这种水平注定是读不懂的,等基础知识足够扎实以后会无师自通?

注: 读的是Android开源项目

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(4)
黄舟

I thought about it and thought it might be that I am not familiar with programming.

Yes, you think so.

So I plan to start with the design pattern.

This is a good idea. But don't expect to be able to "do it all in one battle." It's difficult. To truly understand design patterns and be able to flexibly use them in reality requires many times/long-term repeated learning and practice. Your foundation and talent will help reduce these consumption, but some things really cannot be turned into knowledge just by reading books.

The answer to your question is yes. Although your current "don't understand" is not necessarily because you don't understand programming, the knowledge of software design can always help you, more or less.

Note that design patterns are not all of software design, but only a very important part of it. For a long time in our programming career, we will all go through the stage like you said, "This level is destined to be incomprehensible", but this should not be a reason to stop you from continuing to read the source code.

The so-called "self-taught without a teacher" is unrealistic. There is no set rule for learning programming. It is a manifestation of comprehensive quality. You can't expect to plunge into the "design pattern" pit, and when you climb out, "reading open source projects" will be a matter of course; the same is true in reverse. They should be a mutually reinforcing relationship, somewhat similar to "the combination of theory and practice."

When reading the source code, the focus is not on "Do I fully understand it?" but on "What have I understood? What else don't I understand?" If you understand it, try to use it when you actually do it. If not, Yes, learn the relevant knowledge of software design to understand it. And in view of this, you don’t have to choose a large project to read the source code. Sometimes even a dozen lines of snippets can benefit people a lot - but of course, when it comes to the "design" level, of course it has to be Only at a certain scale can it be reflected.

洪涛

Design patterns are not silver bullets or nine-yin scriptures. It is best not to hold on to the idea that "if you learn design patterns, your programming level will be greatly improved."
Personally, I feel that design patterns are difficult to understand if you have not written a lot of code (not stacking code, but don’t think about it while writing). If you have some coding experience, then you can look at the design mode, there will be a feeling of "I wipe! That's it!"
Design patterns are essentially certain solution patterns for solving certain problems that have been summarized in a large number of software practices. It is not a starting point, but a straw (one of the life-saving straws) when you are stuck in the code quagmire. .
The above is just my personal opinion~

As for learning open source projects, the brother upstairs has already explained it clearly, so I won’t say more. In one sentence: start with the structure and choose modules to read.

GoodOpen source projects allow you to see the art of programming (a little pretentious, but it really feels like this)

Ty80

If it helps, just read Spring

Peter_Zhu

The most important thing about OOP is abstraction.
And design patterns are the results of abstraction. (Personal understanding of design patterns)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!