Sign in to follow this  
CProgrammer

what do you think of the following code design

Recommended Posts

Say we need to have a matrix class for special functionality. The matrix is saved as a size 4x4=16 array of floats: float *mat = new float[16]; Now I've come across to aproaches. 1.) Hide the internal representation completely by using only the class. 2.) work with matrices as float *mat pointers. Then have a class to encapsle it whenever needed like so: Matrix mat(mymat); mat.dosomething(...); I would say I think 1 is better but I'm curious as to whether anyone has any serious reasons not to use 2. I came across this in team projects. Someone used float arrays for matrices and now I have to work with them, so restructure everything or adapt with version 2? -CProgrammer

Share this post


Link to post
Share on other sites
To use a matrix class fully with a graphics API, you'll need to expose the internal storage anyway. For example, opengl expects float*s.

Share this post


Link to post
Share on other sites
Well, GL expects const float*s, so you don't need to expose a mutating access to the internals, just a const one.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this