Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of vector class in Delphi?

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?

like image 1000
jpfollenius Avatar asked Feb 01 '26 10:02

jpfollenius


1 Answers

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.

like image 55
Toon Krijthe Avatar answered Feb 04 '26 00:02

Toon Krijthe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!