OOP Array of Objects vs. Object with Array

1 Ansicht (letzte 30 Tage)
Chris
Chris am 19 Jul. 2017
Kommentiert: Edoardo Patelli am 21 Jul. 2017
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 Kommentar
Edoardo Patelli
Edoardo Patelli am 21 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by