OOP Array of Objects vs. Object with Array
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
All, I spent some time searching around for a similar question but wasn't successful, perhaps I need to work on my search queries.
I am wondering what people's thoughts are on the following topic:
Let's say I have a framework which needs to be designed and coded in Matlab. The framework consists of a "tasking engine" which needs to keep track of various tasks, assign them to other objects to be executed, and collect the results. Each task is similar, but different. The tasks, for example, could be things like Walk, Run, Transport, etc.
One approach to this is to have an abstract class Task, and have Walk, Run, and Transport all inherit from it. I can keep track of all the tasks in a Heterogeneous array. This approach seems more inline with typical OOP style, and seems to be a more organized approach off the bat.
Another approach would be to have a single (non-abstract) class Task, which keeps track of these various tasks in a large array. This class would have to implement logic to determine which tasks are of which type, and execute them accordingly. This approach seems less like traditional OOP style, and more akin to what Matlab was originally designed for.
I'm wondering, do people have a preference for one versus the other? Do you think I can expect a performance difference with one versus the other?
Are there questions I'm missing/forgetting to ask?
For reference, I am using Matlab 2017a.
Thank you in advance,
Chris
1 comentario
Edoardo Patelli
el 21 de Jul. de 2017
You should go for the first option. It will make your code more usable/readable/robust.
Matlab is very different from what it was originally designed for.
Respuestas (0)
Ver también
Categorías
Más información sobre Software Development Tools en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!