vendredi 13 mai 2016

Various interfaces for a single "data-carrying" class

I am trying to implement a series of classes that provide a (common) interface to triangular or symmetric matrices, but I want to avoid copying memory (i.e. make a lot of in-place operations).

The way I was thinking to do this in C++ is to implement a class or struct that is simply a vector containing the matrix data (since I am only concerned on triangular matrices, I only have to store half of the matrix approx.). Let's call this "data-carrying" class SquareTriangularMatrix. Now the data inside this matrix could be accessed differently depending wether the data should be treated as upper triangular, lower triangular or even symmetric.

I do not think that polymorphism can be applied in my case because I want that the same object of SquareTriangularMatrix have different interfaces depending on the context. Some times SquareTriangularMatrix could be treated as a lower triangular matrix, but some others might be its transpose: an upper triangular matrix, and so on.

Is there any design pattern that addresses this problem? Any hint or guideline in this context would be much appreciated.

Many thanks

Aucun commentaire:

Enregistrer un commentaire