Hi all,
I'm new to OOP in MATLAB. When defining properties in a class, shall I define them as constants or as a struct? For example, explicitly:
classdef myClass < handle properties a b c end methods function obj = myClass(a, b, c) obj.a = a; obj.b = b; obj.c = c endend
or as struct
classdef myClass < handle properties prop end methods function obj = myClass(a, b, c) obj.prop.a = a; obj.prop.b = b; obj.prop.c = c; endend
The first way allows me to define attributes, such as private, public, etc. But if there are lots of properties, this way is too long.
The second way I will only be able to define attributes for the entire 'prop', I cannot only define prop.a as private but prop.b and prop.c as public, but the second way seems very neat.
What do you usually do and why?
Thank you!
Best Answer