设计模式与EffectiveJava
我是一名学生,正在努力提高我的 Java 和一般编程技能。我熟悉一些基本的设计模式。
我有两本书《Head First to Design Patterns》和《Effective Java》(Josh Bloch),这两本书都旨在促进良好的编程实践。
然而,我对“我应该如何阅读文本才能最有意义?”感到困惑。
据我了解,设计模式是基础知识,除了一般的设计模式之外,Effective java 还有一些附加实践。
看待整个场景的正确方法是什么?
I am student striving to improve my Java and general programming skills. I am familiar with some of the basic design patterns.
I have two books on my disposal "Head First to Design Patterns" and "Effective Java"(Josh Bloch), both aiming to promote good programming practices.
However I am confused as to "how should I read the texts so that it makes the most sense?"
From what I understand, design patterns are basics and effective java has some addon practices in addition to general design patterns.
What is the right way to look on the entire scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你只需要积累你的知识。其中一些是通过阅读好书,其中乔什·布洛赫的书是一本非常好的书。其中一些是通过在业余时间承担编程任务并关注博客和其他网站(例如 stackoverflow)。虽然其中一些您将通过其他实践经验(即在工作中)获得。
这些事情需要时间并需要经验。只要享受这门语言并沉浸其中即可。模式并不是语言的全部,但它们是有效工具包的一部分。最好充分理解该语言,然后您就会看到设计模式如何帮助解决常见问题并且通常可以更好地解决它们。但绝对不要沉迷于模式,直到您足够了解该语言。事实上,根本不要沉迷于模式!
我想说 Josh Bloch 的书是专注于第一部分的最好的书 - 它非常出色,向您介绍了所有关键概念(常见方法,例如 equals 和 hashcode、枚举、并发),并且还介绍了您将了解的模式今天受益于例如构建器模式。
You just have to build your knowledge up. Some of that is by reading good books, of which the Josh Bloch book is a very good book. Some of it is by taking on programming tasks in your spare time and keeping an eye on blogs and other websites such as stackoverflow. While some of it you will get through other practical experience i.e. at work.
These things take time and come with experience. Just enjoy the language and immerse yourself in it. Patterns aren't the be all and end all of the language - they're part of an effective toolkit though. It's better to understand the language fully, then you will see how design patterns can help solve common problems and often solve them better. But definitely don't get obsessed by patterns, until you know the language well enough. If fact don't get obsessed by patterns at all!
I'd say the Josh Bloch book is the best book to concentrate on 1st - it's excellent and introduces you to all the key concepts (common methods such as equals and hashcode, enums, concurrency) and also introduces patterns which you'll get day to day benefits from e.g. Builder pattern.
我唯一的建议是避免过度杀伤和过度设计。一些经验丰富的 OOP(和 Java)程序员在学习设计模式时将其视为圣经,经常会创建模糊且无用的代码。这看起来很矛盾,但仔细想想,其实不然。
当编程的目标不再是解决问题、生产有用的工具和产生可衡量的结果,而是成为展示一个人的高超技巧、聪明才智,有时甚至是自作聪明时,那么代码就变成了一堆棘手的脑电波对任何人都没用,除了编写代码并看着他疯狂的“白象”感觉很好的人。
我多次看到它们的无用应用。最被滥用的是工厂模式,现在很流行,实际上就像食品调料一样无处不在。
很多时候,我看到类和接口的激增,无用的概括,这是毫无意义的:在某些情况下,我看到包含 2 个有用的类和 10 个接口和/或抽象类的包。我也觉得有必要使代码“通用”和“可重用”,但必须有一个限制。
我多次看到关于这些话题的“宗教战争”。
阅读所有您想要的书籍,并从中获取您需要的内容。但之后,编写合理的代码。写有用的东西,这就是你开始编程的最初原因。
My only advice is to avoid overkill and over-engineering. Some experienced OOP (and Java) programmers that learn design patters taking them as they were the Bible often create fuzzy and useless code. That seems contradictory, but if you think about it, it isn't.
When the goal of programming is no longer resolving a problem, producing useful tools, and having measurable results, but becomes the exposition of one's great sophistication, cleverness, and sometimes smartass egotism, then the code becomes just a bunch of tricky brainwave that is useless to anybody, excluding the one who wrote the code and feels good looking at his crazy "white elephant".
Many times I've seen useless applications of them. The most abused is the factory pattern, that in this moment is quite trendy and in fact put everywhere like a food dressing.
Many times I've seen proliferation of classes and interfaces, useless generalizations, which are pointless: in some cases I've seen packages with 2 useful classes, and 10 interfaces and/or abstract classes. I too feel the need of making the code "generic" and "reusable" but there has to be a limit.
Many times I've seen "religious wars" about these topics.
Read all the books you want, and take from them what you need. But after that, write reasonable code. Write useful stuff, that's the original reason why you started programming.
两本书相辅相成。 《Effective Java》是关于编写 Java 代码的最佳实践。设计模式描述了一组常见软件问题的标准解决方案。设计模式实际上是独立于语言的,而Effective Java 显然专注于java 语言。
但我的总体做法是“始终同意乔什·布洛赫”(除非乔恩·斯基特不同意他的观点)
The two books complement each other. Effective Java is about best practices in writing java code. Design Patters describe a set of standard solutions to common software problems. The design patterns are language independent really, while Effective Java is obviously focused on the java language.
But my general approach is "always agree with Josh Bloch" ( unless Jon Skeet disagrees with him )
编程模式是最佳实践。
应谨慎使用它们。
每个设计模式都试图处理某种形式的变化。
例如,策略模式解决了实施中的变化
这基本上是一种即插即用方法的奇特说法。
模式可以产生灵活的代码,但它们会在代码中产生大量额外的复杂性。
也许您想将《Applied Java Patterns》一书放在您已有的书籍旁边。
它的作者是奥拉夫·马尔森和斯蒂芬·斯泰廷。此外,所有模式的根源都是四人帮,您可能也想使用他们的书作为参考。
Programming patterns are best practices.
They should be used sparingly.
Every design pattern tries to handle some form of variation.
For example strategy pattern tackles a variation in implementation
Which is basically a fancy way of saying it is a plug and play method.
Patterns result in flexible code, but they create a large amount of extra complexity in the code.
Maybe you want to take the book Applied Java Patterns next to those books you already have.
It's written by Olav Maarsen and Stephen Stelting. Also the root of all patterns are the Gang of Four, you might want to use their book as a refference as well.
设计模式并不总是好的。过度使用设计模式是不好的。
然而,乔什·布洛赫(Josh Bloch)总是对的。相信他,你就得救了。
忘记设计模式。乔什·布洛赫(Josh Bloch)的书为您提供了所需的所有模式。
Design Pattern is not always good. Overuse of Design Pattern is bad.
Josh Bloch, however, is always right. Trust him and you are saved.
Forget Design Pattern. Josh Bloch's book gives you all the patterns you need.