Delphi中向量类的实现?
您将如何在 Delphi 中创建向量类?我更愿意将所有与数学相关的东西放入 DLL 中。我应该使用记录还是实现接口的类?
记录方法的优点:
- 快速、轻量级
- 值类型
- 运算符重载
记录方法的缺点:
- 实现不能隐藏在 DLL 中(没有继承,因此 DLL 接口不可能有抽象基类)
- 记录作为类属性的问题 (
Class .VectorProp.X := 42
)
你觉得怎么样?
How would you go about creating a vector class in Delphi? I would prefer to put all math related stuff into a DLL. Should I use a record or a class implementing an interface?
Pros of record approach:
- Fast and lightweight
- Value type
- Operator overloading
Cons of record approach:
- Implementation cannot be hidden in DLL (no inheritance, so no abstract base class for the DLL interface possible)
- Problems with records as properties of classes (
Class.VectorProp.X := 42
)
What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您的优先事项。
如果性能是重中之重,那就去查看记录。但如果实现隐藏是最重要的,那么就选择接口。
但是为什么不使用包,这样您就可以根据需要同时使用静态和动态链接。当然,如果代码要被其他语言使用,DLL是首选,DLL是更好的方法。
底线是,需求及其相对优先级决定了实施。
It depends on your priorities.
If performance is a top priority, go for records. But if implementation hiding is top, go for interfaces.
But why not use a package so you can both use static and dynamic linking if you want it. Of course, a DLL is prefered if the code is to be used by other languages, a DLL is a better aproach.
Botom line, the requirements and their relative priority determine the implementation.
我没有使用过其中任何一个,但它们可以节省您一些时间。
I haven't used either of these, but they could save you some time.