你在我的设计中看到任何(反)模式吗? 如何识别图案?
我有一个用 ABAP / BSP 编码的 Web 应用程序。 我有兴趣提供好的代码,所以也许你可以帮助我识别一些好的或坏的模式。 实际上我确实在关注。 声明一个基类对象并根据子类的某些参数动态实例化它。 基类有一些用于获取数据的方法(),子类使用这些数据并可能对其进行操作。
这里有一些快速的基本图片(抱歉,我不认为它符合任何标准或语言,但应该给你一个想法)
替代文本 http://img35.imageshack.us/img35/4351/designkdp.jpg
这样可以吗? 是否隐藏了任何已知的模式,或者我应该重构并使用模式? 我喜欢这里一些建议。 我已经阅读了维基百科文章,但我没有看到完全适合的模式。 (还订购了一些书,但你们肯定更快:))
i have a Web App coded in ABAP / BSP. I´m interested to deliver fine code so maybe you can help my recognize some good or bad pattern. Actually i do following. Declare a base class object and instantiate it dynamically based on some parameter with a sub class. The base class has some methods for data fetching () the sub classes use this data and maybe manipulate it.
Here some fast basic picture (sorry dont think its conform to any standard or language but should give you an idea)
alt text http://img35.imageshack.us/img35/4351/designkdp.jpg
Is somthing like this OK? Is there any known pattern hidden or should i refactor and use a pattern? I like to here some suggestions. I have already read the Wikipedia article but i dont see a pattern fit exactly. (Also ordered some books but you guys are sure faster :) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这似乎是一个工厂方法
It seems a factory method
在我看来,基类和子类就像有一些东西(伪代码)
您使用的实例化策略似乎像 工厂。
你可以做的就是在一些 HTMLRenderingEngine 或其他东西中布局渲染(我不熟悉 ABAP/BSP),只是为了将演示文稿与其余逻辑分离。
The BaseClass and SubClasses seem to me like having something as (pseudocode)
The instantiation strategies you use seem to work like a Factory.
What you could do is to lay out rendering in some HTMLRenderingEngine or whatever (I'm not familiar with ABAP/BSP), just to have the presentation decoupled from the rest of the logic.
这是 Gamma、Helm、Johnson 和 Vlissides 所著的《设计模式:可重用面向对象软件的元素》一书中的工厂模式。
This is the Factory pattern from the book "Design Patterns: Elements of Reusable Object-Oriented Software" by Gamma, Helm, Johnson and Vlissides.
继承很有趣,但应该作为最后的手段。 我并不是说你不能按照你的方式去做——你的解决方案是完全有效的,但只是建议一个替代方案......
如果你有“DataClass”,你可以在其中设置一个 processData 对象(或不)。 processData 对象实际上是一个具有单一方法“processData”的接口。
当您调用 getData 时,它可能看起来像这样:
哎呀,如果您定义了一个不执行任何操作的“passthrough”processData 对象并将其用作默认的“processDataObject”,那么整个 getData 方法将变为:
这将允许动态创建类来执行您想要的任何类型的处理——它将简化您在此设计之上构建的内容。
这种设计风格花了我一段时间才适应,你一开始可能不喜欢避免继承的想法,我只是要求你考虑一下。 这些天我很少使用继承,当我使用它时,它总是在非常浅的树中。
Inheritance is fun, but should be used as a last resort. I'm not saying you can't do it the way you did--your solution is totally valid, but just to suggest an alternative...
What if you had "DataClass" in which you could set a processData object (or not). The processData object would actually be an interface with a single method "processData".
When you call getData, it might look something like this:
Heck, if you have a "passthrough" processData object defined that does nothing and use that as the default "processDataObject", then the entire getData method becomes:
This would allow dynamic creation of classes to do any type of processing you want--It will simplify things that you build on top of this design.
This style of design took me a while to come to terms with, and you may not like the idea of avoiding inheritance at first, I'm just asking you think about it. My use of inheritance is pretty rare these days, and when I use it, it's always in very shallow trees.