Middleware Development Help

Started by
11 comments, last by Sphet 15 years, 6 months ago
Alright, I just need some quick help with some of my development concerns. Right now I am developing some middleware, and as everyone knows, middleware should be easily integrated into existing engines. Basically, I want the user to be able to "plug" their own implementations for vectors, matrices, file handling, and other things into the middleware, and then the middleware will use their implementation. So my solution: I create an abstract interface for the user implementation to adhere to, and then I create an abstract interface for a factory class, with one function, that the user must implement. The user then registers their factory class, and the engine uses that factory class to create the objects without any idea of the underlying implementation. Does this seem reasonable? Is there a better way to do it?
Denzel Morris (@drdizzy) :: Software Engineer :: SkyTech Enterprises, Inc.
"When men are most sure and arrogant they are commonly most mistaken, giving views to passion without that proper deliberation which alone can secure them from the grossest absurdities." - David Hume
Advertisement
I suspect that an abstract interface for matrix and vector handling will incur too much overhead. You'd want them to write a 3D vector factory, for example? And would those vectors have to derive from your base class?
Yes, currently, they have to derive from the base class. And that's exactly what I was afraid of, the overhead.

So any suggestions on how I would gaurantee that the user's implementation has specific functions, such as normalize(), dotproduct(), etc.?
Denzel Morris (@drdizzy) :: Software Engineer :: SkyTech Enterprises, Inc.
"When men are most sure and arrogant they are commonly most mistaken, giving views to passion without that proper deliberation which alone can secure them from the grossest absurdities." - David Hume
provide templates that require them.

provide the classes yourself then all they have to do is write conversion constructors or use them as is.
Forcing vector, matrix and file handling class' to derive from your base class is just bad design, take some time to learn what good middleware design involves. For example this blog post by Kyle Wilson and the presentation I link to in the comments.

edit: link fixed
Quote:Original post by stonemetal
provide templates that require them.

provide the classes yourself then all they have to do is write conversion constructors or use them as is.


I don't quite understand your first explanation, can you explain that. And your second example does seem alright, but then the class I provide does not use their implementation, which could be optimized for some special cases or something.

Quote:Original post by dmail
Forcing vector, matrix and file handling class' to derive from you base class is just bad design, take some time to learn what good middleware design involves. For example this blog post by Kyle Wilson and the presentation I link to in the comments.


That link doesn't work.
Denzel Morris (@drdizzy) :: Software Engineer :: SkyTech Enterprises, Inc.
"When men are most sure and arrogant they are commonly most mistaken, giving views to passion without that proper deliberation which alone can secure them from the grossest absurdities." - David Hume
Quote:Original post by dmail
Forcing vector, matrix and file handling class' to derive from your base class is just bad design, take some time to learn what good middleware design involves. For example this blog post by Kyle Wilson and the presentation I link to in the comments.
That link is going in bookmarks forthwith.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by swiftcoder
Quote:Original post by dmail
Forcing vector, matrix and file handling class' to derive from your base class is just bad design, take some time to learn what good middleware design involves. For example this blog post by Kyle Wilson and the presentation I link to in the comments.
That link is going in bookmarks forthwith.


Odd, it works for me now too. I guess I will have a read then.

EDIT:

Ah, you fixed the link, that's why. But at any rate, I have read that article before when I was searching the internet for answers to my question. This is the exact reason why I wrote, "Basically, I want the user to be able to "plug" their own implementations for...file handling..."

Currently, I have no answers on how to do this efficiently.
Denzel Morris (@drdizzy) :: Software Engineer :: SkyTech Enterprises, Inc.
"When men are most sure and arrogant they are commonly most mistaken, giving views to passion without that proper deliberation which alone can secure them from the grossest absurdities." - David Hume
Did you also listen to the presentation?
If you are going to be doing matrix and vector operations then you need to use you own representation (or a well defined implementation), yet not force the user of your library to have to use it. Instead give them options by supplying more than one method of informing you of a matrix or vector.
Most math libraries have a conversion to a block of data from a class in the form of float* or double* so having this option is really a must. The presentation makes the point of writing user code before library code, ie what will your uses have to do, so ...
enum MATRIX_ORDER{ROW,COLUMN}; void Lib::bar(float*);void Lib::set_matrix_order(COLUMN);//initialise the lib...//user codeD3DXMATRIX foo;Lib::bar(foo);//D3DXMATRIX has the conversion and the library knows the layout.

You could also support the DirectX math library directly in a windows build or at least give the user the option, possibly also giving the user the _option_ of using your libraries fancy matrix type. Another possibility is to document your matrix type and say to the user here is a abstract class derive from it with an implementation of converting from my type to yours and vice versa and tell the library about it. You could also have an option which accepts 16 floats or ...
Quote:Original post by Halifax2
Basically, I want the user to be able to "plug" their own implementations for vectors, matrices
Don't. I've seen it tried, and it doesn't work, and it sucks. Manually written conversion functions, mildly annoying though they may be, are the way to go. Just make sure to store your matrices in the same order as everyone else, so that conversion functions are no-ops.
Quote:file handling

This one's a better idea, and it's also a lot easier. The way you proposed will work fine. Consider, though, how streaming will affect things.

This topic is closed to new replies.

Advertisement