フィルターのクリア

OOP Array of Objects vs. Object with Array

1 回表示 (過去 30 日間)
Chris
Chris 2017 年 7 月 19 日
コメント済み: Edoardo Patelli 2017 年 7 月 21 日
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 件のコメント
Edoardo Patelli
Edoardo Patelli 2017 年 7 月 21 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by