Advise on how to structure different classes. I'm OO newbie
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Adam
2017-2-8
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 个评论
Adam
2018-8-20
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!