OOP Array of Objects vs. Object with Array

조회 수: 3 (최근 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 CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by