Advise on how to structure different classes. I'm OO newbie

I have between 1 and 1500 oscilloscope traces that make up a 2D-dataset that is associated with a lot of other parameters (eg X, Y, Z-position, thickness, etc), so I thought that I would use a classes to structure it all. I want to perform different calculations on/based on the data like, spectral analysis and some other operations eg find peaks (or lines in the 2D image) automatically.
I've heard somewhere that it's bad to have a so-called god-object, so I thought I would separate the classes for storing the data from the class performing the spectral analysis etc. What is the best way to make the class that performs the spectral analysis access the data in the "Storage class"? Or should I make the spectral analysis inherit from the storage class? Or do I have it all wrong, maybe there's a much better way to set up my classes?
Thanks in advance/M

 Réponse acceptée

Don't have a calculator class inherit from a data class.
Either just give public access to what is in the data class, give access to specific classes e.g.
properties( SetAccess = private, GetAccess = ?SpectralAnalysisClass )
or if you wish you could have some generic function on your data class that allows you to pass in a function handle to act on the data. Then you can keep the data private, but it can get complicated if you have lots of properties and functions wanting to access different of them.

5 commentaires

Ok thanks, sounds resonable.
One more question then, if:
A=myDataClass('file.dat'); % creates obj (and imports the file.dat)
Should I pass the object to the SpectralAnalysisClass like this
SpectralAnalysisClass.myFFTfunction(A)
Yes
Micke Malmström
Micke Malmström le 19 Août 2018
Modifié(e) : Micke Malmström le 19 Août 2018
Thanks for all the guidade so far... I now have
  • a data class
  • A temporal analysis class
  • A plotting class
  • A spectral class that inherit from the data class
  • A spectral analysis class
  • A plotting class for the spectral analysis.
Now I want to expand the set to be able to perform another type of calculation and with that i’m Going to need a few new “properties” so I thought I would create a new storage class for the data and properties that is needed for this new type of analysis. What is the best way of enabling new analysis capabilities to the original storage class without filling it up with new properties that is seldom used? Should I make a new storage class that inherit from the original or should I make a new “property” class that by default is empty until needed? Or is there another completely different and much smarter way of doing it?
It's very hard to know in a general situation, it depends on the specifics of what you want to do and what you currently have. Certainly having properties on a class that are only used by one specific other class or function is not the kind of design you would want. Inheritance to give an extended class may work well or a different solution could be better, using aggregation/composition rather than inheritance.
Thanks! I’ll look in to aggregation/composition.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Analysis dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by