MATLAB Object Oriented Programming Composition vs Association

What would be the best way to design a class in MATLAB (such as a rocket) so that it can have objects as part of itself (such as how a rocket has a thruster) and objects that it merely interacts without being part of itself (such as how a rocket gravitationally interacts with a planet without the planet being part of the rocket)? In other words how can I design a class so that some of the parameters "compose" the class while others are merely "associated" with the class? I know with C++ you can simply use pointers to distinguish between these two, but as far as I know there is no such mechanism in MATLAB. Ideally I would also like it so that a object associated with another would could still be used to compose a different object (Such as how a planet can compose a solar system while merely being associated with a rocket via gravity).

May 19, 2025 - 23:40
 0

What would be the best way to design a class in MATLAB (such as a rocket) so that it can have objects as part of itself (such as how a rocket has a thruster) and objects that it merely interacts without being part of itself (such as how a rocket gravitationally interacts with a planet without the planet being part of the rocket)? In other words how can I design a class so that some of the parameters "compose" the class while others are merely "associated" with the class? I know with C++ you can simply use pointers to distinguish between these two, but as far as I know there is no such mechanism in MATLAB. Ideally I would also like it so that a object associated with another would could still be used to compose a different object (Such as how a planet can compose a solar system while merely being associated with a rocket via gravity).