views:

203

answers:

2

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?

+1  A: 

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.
Lawrence Barsanti
Thanks even though this is not an answer to my question.
Smasher
+2  A: 

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.

Gamecat
+1 Accepted. I assumed that there is no "right" way. I'll have to think about my priority here. Thanks!
Smasher
The right way depend on your requirements. Sometimes they are conflicting so you have to be creative.
Gamecat