in MATLAB I have different classes A & B. I want to assign objects created from class A & B as properties in both A & B . My code looks like this
classdef A < handle
properties
container
end
methods
function object = A()
end
end
end
and this
classdef B < handle
properties
container
end
methods
function object = B()
end
end
end
Then I am assigning both objects from class A & B to the container-property from both classes A & B, like
object_from_class_A.container = object_from_class_A
and
object_from_class_A.container = object_from_class_B
This means, I use the same variable/property for storing objects from different classes. Is this a bad design choise? How should I avoid this? I am just trying to assign objects to each other, because I am trying to build relationships between different objects.
P.S. I am new to OOP.
Edit for better explanation:
Class A & B are fundamentally different and should not be connected/inherited from each other. I have something in mind like this: Object city contains object street and object house, object house is connected to object street. So, street and house should inherit from city, but street and house should know each other. But how should I realize the relation between many objects (like sign, car, people, cat, dog, etc) that all inherit from city but dont share/inherit anything else between each other?
For example I want to establish a connection beween a car an an street object, so if I look into a specific street-object, I want to assign the specific objects car1, car2, car3 to the street object.
streetandhouseshould inherit fromcity". I disagree. Those three items are fundamentally different entities, albeit related. I would say make them their own classes, and havecitycontain, or in OOP terminology "be composed of",streetarrays andhousearrays. - TroyHaskin