Design patterns don't go directly into your code, they first go into your BRAIN. Once you've loaded your brain with a good working knowledge of patterns, you can start to apply them to your new designs, and rework your old code when you find it's degrading into an inflexible mess of jungle spaghetti code.
First look at the project, think of a top-level design that fits the real world requirements. Then (with your brain loaded with patterns) you'll see the patterns inside the design and will know which patterns to use.
Please, don't build your design around beautiful patterns. With one exception: The technology, you've mentioned, comes with some best practice patterns. You should know them and use them (most of them are build in the frameworks anyway and you can't avoid using them). For those you should know and use them, because others expect those patterns when the see a design based on spring, JPA, J2EE, ...
Applying design patterns is a question of personal experience, and to some extent style and preference too. It just takes practice to learn it, there are no fast lanes to the knowledge, sorry :-) Of course, books and stories from others are a good source of information - but only that. You need to learn how and when to apply all that information. The best learning experiences are one's own mistakes, so don't fear of making mistakes.
If you want to collect war stories though, you may want to ask this on programmers.stackexchange.com.
Patters for integration these technologies are well defined in tutorials and manuals. There is really no much space for big changes. Have a look at following links to get an understanding:
As soon as you have done all integration using described techniques, you may play with it a little bit to make it more suitable specifically for your purposes.
These technologies their self are pushing to to use some set of patterns. Have a look at these questions for more details:
发布评论
评论(3)
来自Head First - 设计模式:
首先查看项目,考虑适合现实世界需求的顶层设计。 然后(当你的大脑充满模式时)你将看到设计中的模式,并且知道要使用哪些模式。
请不要围绕美丽的图案构建您的设计。但有一个例外:您提到的技术带有一些最佳实践模式。您应该了解它们并使用它们(无论如何,它们中的大多数都是在框架中构建的,您无法避免使用它们)。对于那些你应该了解并使用它们的人,因为其他人在看到基于 spring、JPA、J2EE 的设计时期望这些模式......
A short quote from Head First - Design Patterns:
First look at the project, think of a top-level design that fits the real world requirements. Then (with your brain loaded with patterns) you'll see the patterns inside the design and will know which patterns to use.
Please, don't build your design around beautiful patterns. With one exception: The technology, you've mentioned, comes with some best practice patterns. You should know them and use them (most of them are build in the frameworks anyway and you can't avoid using them). For those you should know and use them, because others expect those patterns when the see a design based on spring, JPA, J2EE, ...
应用设计模式是个人经验的问题,在某种程度上也是风格和偏好的问题。只需要练习就可以学习它,知识没有捷径,抱歉:-) 当然,书籍和其他人的故事是很好的信息来源 - 但仅此而已。您需要了解如何以及何时应用所有这些信息。最好的学习经验就是自己的错误,所以不要害怕犯错误。
如果您想收集战争故事,您可能想在programmers.stackexchange.com上询问。
Applying design patterns is a question of personal experience, and to some extent style and preference too. It just takes practice to learn it, there are no fast lanes to the knowledge, sorry :-) Of course, books and stories from others are a good source of information - but only that. You need to learn how and when to apply all that information. The best learning experiences are one's own mistakes, so don't fear of making mistakes.
If you want to collect war stories though, you may want to ask this on programmers.stackexchange.com.
教程和手册中明确定义了这些技术的集成模式。确实没有太多的空间进行大的改变。查看以下链接以获取理解:
http:// /static.springsource.org/spring/docs/3.0.x/reference/orm.html
http://static.springsource.org/spring/docs/3.0.x/reference/web-integration.html#struts
一旦你使用所描述的技术完成所有集成,您可以稍微使用它以使其更适合您的目的。
他们自己正在推动这些技术使用某些模式。查看这些问题以了解更多详细信息:
什么设计Spring 框架中使用了哪些模式?
Hibernate 遵循哪种模式?
以及正如已经提到的,应用设计模式是一个经验和大脑的问题;)它迟早会到来。
Patters for integration these technologies are well defined in tutorials and manuals. There is really no much space for big changes. Have a look at following links to get an understanding:
http://static.springsource.org/spring/docs/3.0.x/reference/orm.html
http://static.springsource.org/spring/docs/3.0.x/reference/web-integration.html#struts
As soon as you have done all integration using described techniques, you may play with it a little bit to make it more suitable specifically for your purposes.
These technologies their self are pushing to to use some set of patterns. Have a look at these questions for more details:
What design patterns are used in Spring framework?
Which pattern does Hibernate follow?
And as already mentioned, applying design patterns is a matter of experience and brain ;) It will just come sooner or later.