I am creating a Matrix class that represents a matrix and I have a problem with OOP concept.
which way is the best for representing matrix determinant ?
1. create a property that represents matrix determinant.
2. create a member function that returns matrix determinant.
3. create a library that performs matrix operations and within it, create a function that returns a matrix determinant.
Or for example Transpose that is not as common as determinant:
1. create a member function that returns matrix transpose.
2. create a library that performs matrix operations and within it, create a function that returns a matrix transpose.
this is just an example, but I have this problem in all my OOPs.
Thanks

VulpesPosted Aug 16, 2011, 2:59 PM
Exceptions should only be thrown if an 'exceptional event' occurs.
Square matrices are rarer than non-square ones so, in theory, you'd be throwing an exception more often than not if you use approach #2.
My personal preference is also to throw exceptions as little as possible to minimize the opportunities for the application to 'blow up' in the hands of the end-user.
Majid KamaliPosted Aug 16, 2011, 1:24 PM
I have two ways now:
1. derive a square matrix from a matrix base class and then create a read-only property named determinant.
2. create a generic matrix and a read-only property named determinant and if matrix rows and columns are not equal and then we call determinant property, it generates exception.
Which is better and why?
Thanks for your answers
VulpesPosted Aug 16, 2011, 11:49 AM