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

조회 수: 1 (최근 30일)
Micke Malmström
Micke Malmström 2017년 2월 8일
댓글: Micke Malmström 2018년 8월 23일
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

채택된 답변

Adam
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
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.
Micke Malmström
Micke Malmström 2018년 8월 23일
Thanks! I’ll look in to aggregation/composition.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by