How to manage multiple objects of multiple types at one place?

15 views (last 30 days)
Hello to all,
my question will be rather philosophical than technical - I am looking for an inspiration how to design a software with GUI for data processing. I have several measuring instruments, each has various signals and each instrument has different time base (1 sample/min, 1sample/sec...). The data are stored in daily raw-data files. I have small classes which describe each signal and bigger classes which describe each instrument. Signals objects are inside the Instrument objects.
I have a GUI where I can select available instrument, then available signals for the chosen instrument and I can display data, brush it and do other modifications. But only for one selected day = one object of each instrument. Now I want to do the same but with multiple day data. Loading it, displaying, brushing etc. Unfortunately, day data from some instruments can be missing.
I started to write class DataBundle which will manage all day-data objects from all instruments. But I don’t know how to elegantly solve missing day-data-objects in some days. How to do it? Put objects in DataBundle class to an instrument-dedicated array and always check if the element in the array ~isempty() when plotting? I feel there will be a lot of disorganized code in this solution...
Or should I write a higher class for each instrument that can manage the data as a continuous signal over multiple days and not day-data glued together in an array? But still there is the problem with the missing days – should I use something like empty object full of NaNs to manage it as continuous signal? But the size of empty objects is then too big and useless..
Do you have any idea how to elegantly manage multiple objects of the same type combined with multiple objects of other type?
Also any literature recommendation about general class designing would help me a lot.
I will be happy to provide more details if you need. I miss a long experience with classes designing...
Thanks to all in advance...
Petr

Accepted Answer

Adam
Adam on 10 Apr 2015
Edited: Adam on 10 Apr 2015
is the Matlab OOP documentation I refer to regularly (though less so with more experience now).
Regarding your specific problem, it is difficult to suggest between managing data from multiple days on a higher level vs your first approach as I don't have enough knowledge of the full problem (nor enough time to fully consider that).
In terms of dealing with null data though, if you don't want to have to deal with having e.g.
Instrument1Class.empty
objects in an array of Instrument1 objects you could use more of a design pattern from other languages (you have to crowbar it a bit in Matlab since polymorphism isn't strictly a thing) by using a NullClass version of your main class. You can use inheritance from
matlab.mixin.Heterogeneous
on a base class to allow object arrays of different derived types.
Then something like (kind of pseudo-code but should be mostly Matlab syntax):
classdef Instrument1Base < matlab.mixin.Heterogeneous
Then as another class, your main implementation...
classdef Instrument1 < Instrument1Base
properties
data
end
methods
function plot( obj )
plot( obj.data );
end
end
...
end
Then as the final part of the hierarchy the null version:
classdef NullInstrument1 < Instrument1Base
methods
function plot( obj )
end
end
end
i.e. a hierarchy of 3 classes for 1 instrument (annoying in Matlab language admittedly).
The base class does nothing at all, although you may wish to define abstract functions on here as you would if it were an interface in some other language.
The main class is whatever you have now. I just put a basic plot function as an example.
The null class defines a plot function, but does nothing (you may need it to do something, but basically it will do whatever is sensible for when you have no data).
The idea is that an object of the null class can still call plot so no need to keep checking for emptiness. But that call to plot will just do nothing (or whatever you choose).
You can happily create an array as e.g.
instrumentArray = [Instrument1Base(), Instrument1Base(), NullInstrument1(), Instrument1Base];
due to the base class inheritance from matlab.mixin.Heterogeneous (which is the reason that seemingly pointless base class is needed).
Not sure if that helps at all, but it is at least an idea for you to chew over or someone else to improve upon.
  4 Comments
Adam
Adam on 11 Apr 2015
Yes, you are certainly free to plot lines with different numbers of points so just two NaNs should be sufficient if you need data in there, but I would have thought you could do without data at all though I do not know all the details of your data.
Can you not simply leave a gap in the plot so long as the day 3 plot starts at the correct time on the x axis you will just have a gap in your plot for day 2 coming from a plot function that either does nothing or does whatever is needed to ensure that the day 3 plot will start at the correct point on the graph (though I would assume the responsibility for that is with the day 3 object anyway).
Petr Dvorak
Petr Dvorak on 13 Apr 2015
OK, I don't know why I got stuck on the NaNs plotting idea. I will plot each day, each signal separately with correct x-axis. Then, I don't have to do silly work with empty objects. I will write a class or maybe an Abstract class or Interface to access subclasses data and it's done. Thank you for discussion, it lead to a final decision. Thanks Adam and have a nice day.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!