Delphi中向量类的实现?

发布于 2024-08-17 00:55:44 字数 293 浏览 9 评论 0原文

您将如何在 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 技术交流群。

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

发布评论

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

评论(2

谈场末日恋爱 2024-08-24 00:55:44

这取决于您的优先事项。

如果性能是重中之重,那就去查看记录。但如果实现隐藏是最重要的,那么就选择接口。

但是为什么不使用包,这样您就可以根据需要同时使用静态和动态链接。当然,如果代码要被其他语言使用,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.

遗失的美好 2024-08-24 00:55:44

我没有使用过其中任何一个,但它们可以节省您一些时间。

  1. SDL MathPack - 不确定是否需要付费
  2. Jedi Math - 看起来该项目已被放弃,但无论如何你都应该检查一下。如果你不做任何疯狂的事情,它可能会对你有用。

I haven't used either of these, but they could save you some time.

  1. SDL MathPack - not sure if you would have to pay for it
  2. Jedi Math - looks like the project has been abandoned, but you should check it out anyway. If your not doing anything crazy it will probably work for you.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文