需要框架设计指导

发布于 2024-10-15 02:29:28 字数 169 浏览 1 评论 0原文

我已经进入设计模式相当一段时间了(比如 4 个月),并且在我们的项目中实现了许多设计模式。我已经获得了知识(虽然目前不会说自己是大师)并且我相信我对它们有很好的控制力。

我正在考虑逐步将这些知识转移到框架设计中。但我对此没有任何经验。

你们能指导我至少完成最初的步骤吗?

谢谢

I have been into the design pattern for quite sometime (say 4 months) and has implemented many in our project. I have gained knowledge(though won't say myself as a master at present) and I believe that I have good control over them.

I am thinking to gradually move this knowledge into framework design. But I donot have any experience on that.

Could you people please giude my in making atleast the initial steps.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

且行且努力 2024-10-22 02:29:28

好的框架需要使用一些设计模式,这可能是必不可少的。

比方说 - Spring MVC。很明显,您将使用 MVC。

就说 GWT 吧。 GWT 最好与 MVP 一起使用。

就说休眠吧。您将使用 DAO。 (有人说根据核心定义它不是真正的设计模式,但现在全球都将其视为设计模式)

等等。没有真正的食谱。我会给你一些我的想法,你可能会将它们视为使用设计模式的一些“步骤”:

  1. 理解它们,读一本书。
  2. 了解日常图书馆。例如,Java SE 中使用了大量的设计模式。 BalusC 对此提供了非常好的答案,查看一下。我认为这是特别重要的一步
  3. 选择一个你需要的框架,学习它。 阅读文档,阅读书籍。查看作者及其创建者的推荐。
  4. 遵守良好做法。 Fe DRY、单元测试等。设计模式的真正需求会突然出现。你甚至不会注意到:)这不像“哦,我要实现这个很酷的模式”,而是“这很糟糕,我需要改进它,哦,好吧,让我们看看这就是我需要的!”
  5. 始终保持事情简单。考虑灵活性、可重用性,但始终考虑简单性。使用清晰简单的 API 会更好,因为它的行为是可预测的。

The good framework will require using some design pattern, it might be essential for it.

Let's say - Spring MVC. It's quite obvious, you'll be using MVC.

Let's say GWT. GWT is best used with MVP.

Let's say Hibernate. You'll be using DAO. (Some say it's not real design pattern by core definition, but it's globaly considered as design pattern nowadays)

And so on. There is no real reciepe. I'll give you some of my thoughts, you might consider them as some 'steps' in using design patterns:

  1. Understand them, read a book.
  2. Understand every day libraries. For example, those in Java SE use plenty of design patterns. BalusC provided really great answer about this, check it out. I think this is particularly important step.
  3. Pick a framework you need, learn it. Read the docs, read the book. See recommendations of authors, of it's creators.
  4. Obey good practices. F.e. DRY, unit testing and so on. The real need of design pattern will just pop out. You wouldn't even notice :) It's not like 'oh Im gonna implement this cool pattern', it's like 'this sucks I need to improve it, oh well let's see this is what I need!'.
  5. Always keep things simple. Think of flexibility, reusability, but always think of simplicity. It's much better to work with clear and simple API, where it's behaviour is predictable.
无语# 2024-10-22 02:29:28

框架设计比应用程序设计困难得多。我刚刚在我的博客上写了一篇关于它的文章,并提出了我遵循的框架设计的三个理想。

  1. 在发布之前确保设计正确
  2. 保持可见的 sdk 较小且易于使用重点
  3. 使 sdk 易于使用

第 1 点和第 2 点很重要,因为一旦发布版本,重构可见的 sdk 会导致重大更改。如果您希望开发人员使用您的 sdk,第 3 点很重要。
对我来说,这些理想支配着我在框架设计中做出的每一个决定。在整个过程中我必须一遍又一遍地考虑它们。我在文章中提出了一些实现这些目标的技巧。

框架/SDK/API 设计技巧

在设计模式方面,我想我遵循了与你类似的道路。几年前,我了解了设计模式,并意识到它们有多么强大(和破坏性)。我在一些程序中使用了一些,并最终在框架上使用了一些。我发现在我的框架中,我有机会应用我没有在应用程序中使用的新模式(我突然想到,我只能想到模板方法,并且我相信我在框架中使用工厂的次数比但我不记得所有的细节)。

祝你好运。我认为框架设计是困难的,但也是有回报的。

免责声明:我不是框架设计方面的专家……只是我涉足过的一些东西。

Framework design is much more difficult than application design. I just wrote an article on my blog about it and came up with three ideals that I follow for framework design.

  1. Get design correct before a release
  2. Keep the visible sdk small & focused
  3. Make the sdk easy to use

Points 1 and 2 are important because once a release is made, refactoring the visible sdk results in breaking changes. Point 3 is important if you want developers to use your sdk.
For me, these ideals govern every decision I make in my framework design. I had to consider them over and over throughout the whole process. I put a bunch of tips in my article to achieve these goals.

Framework/SDK/API Design Tips

In terms of design patterns, I think I followed a similar path to you. I learned about design patterns a few years ago and realized how powerful (and destructive) they can be. I used some in some programs, and eventually got to use some on a framework. I found that in my framework, I got a chance to apply new patterns that I did not get to use for applications (off the top of my head, I can only think of template method and I believe I used factories more in my framework than in an application. I can't remember all the details though).

Good luck. I think framework design is difficult but also rewarding.

Disclaimer: I am not an expert in framework design...just something I've dabbled in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文