search

Home  >  Q&A  >  body text

java - 如何学习设计模式?

都说设计模式很重要,但是对于一个刚入门经验不足的新手,如何有效的学习设计模式,请大神们指教一二?

大家讲道理大家讲道理2802 days ago1321

reply all(12)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:31:33

    Just reading books will not make you a person who is proficient in design patterns, let alone being able to apply them to actual projects immediately
    It is recommended to read more open source code and understand how design patterns are applied in other people’s codes. In fact,
    the designs that are actually used Patterns are often variations of the 23 design patterns. They are not just based on books. JDK source code is a good material for learning design patterns
    Through
    , you can learn the decorator patternjava.io.*Through the jdbc api, you can learn the bridge mode
    Looking at the Proxy code in java, you can learn the proxy pattern
    etc...

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:31:33

    It is recommended to read this book "Dahua Design Patterns" first to understand why design patterns are used.

    This requires accumulation of experience, daily thinking, application and improvement little by little. Don’t copy it just to use the design pattern.

    Simply put, design patterns are a summary of methods to solve common problems. Note that I am talking about common problems, and our needs are often complex and diverse, so we often use multiple design patterns together, or do it flexibly according to our own needs, and we do not necessarily follow the pattern method.

    Elegance, efficiency, and practicality are what we pursue, so design patterns are very important. They allow us to think about problems more abstractly.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:31:33

    Now I bought a copy of "Head First Design Pattern". . As a novice, let’s read this book first to get familiar with it. .

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:31:33

    Let me tell you why it’s important first:

    • A lot of design patterns are used in some mainstream frameworks. If you don’t understand design patterns, it will be very difficult to understand the principles of the framework

    • Reduce code redundancy, make code easy to expand, etc.

    Let’s talk about books again:

    • "Dahua Design Patterns" is okay, the language in it is C#, but C# is very similar to Java

    • I read the book "Zen of Design Patterns (2nd Edition)" and I think it's pretty good. It's written in Java

    • The latest book in the diagram series - "Illustration Design Pattern". The diagram series is very friendly to novices and is also written in Java. It is recommended

    Of course, you can also go to MOOC to watch some videos about design patterns. It's pretty good.

    Then what you have to do is to write more code and think about which codes can use which design patterns. Don't just imagine it. To apply it in actual combat, it is not advisable to talk on paper.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:31:33

    Not a lot of coding practice, think carefully

    Learning design patterns is like designing a "castle in the air"

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:31:33

    Look at the examples and write an example, as if this is a common way to learn coding.


    Here is a tutorial that introduces each mode and gives examples. Try finding another situation yourself to apply these patterns. Of course, don’t overuse it. To A Man with a Hammer, Everything Looks Like a Nail.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:31:33

    Design pattern is a summary of some experiences in use, which can solve problems in a specific context.

    First we need to understand what problem it can solve? How to solve it? Advantages and Disadvantages? Write a few small examples yourself, and then you can look at the use of design patterns in Java class libraries and the use of design patterns in open source frameworks.

    In short, read more, write more and think more.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:31:33

    Don’t learn design patterns for newbies, you have more important things to learn. You need to first become familiar with the language you use, then become familiar with the usage of the framework class library you use, then accumulate a certain amount of code, and then learn design patterns.

    Thoughts are based on language. If you are not proficient in language, your thoughts will be like castles in the air.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:31:33

    There is a big talk about PHP design patterns on MOOC. I think it is very clear. Using many examples, you will find that you often use various design patterns unintentionally during the coding process.

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:31:33

    If you have code implementation, you can learn it. Otherwise, wait until you accumulate some experience before learning. Otherwise, you will just do it behind closed doors. Even if you learn it, you don’t know where to use it. When is it better to write a factory? When is it better to use the observer pattern? Watching porn movies for more than 20 years is not as good as actually having sex once, so if you have insufficient development experience, it is useless to have theories unless you can directly use the pattern in the code you are working on now. Otherwise, just take a brief look at it, and when you really need it, you can remember that something like this may be useful, and then study it in detail. In that case, whether to use the mode in XXX situation will be the second thing you need to think about. Question

    reply
    0
  • Cancelreply