I'm struggling with an implementation of Matlab's OOP and object composition. For simplicity I'll use a car example. Im constructing a of series classes. One is a kind of Master class (like a car) and a series of other classes, (tire, window, door, etc). When I give the car properties using said objects, I'm having trouble updating the properties of the car parts. If for example a property of the car changes AND that change affects its tire property class how should this be handled?
I'm assuming I need use listeners but am concerned it may be overkill for what I am trying to achieve. However I can't wrap my head around this if things get more and more intertwined- Ex: a tire now has a hubcap property that is an object and its color property is dependent on the color of the car and so on and so on.
Any help with this is appreciated and I can provide clarification if necessary but I'm hoping someone will recognize either the flaw in my construction or what approach best handles this. Thanks!
%define a car
classdef car < handleproperties tiredoorwindowpaintcolorOfCarend%In another file Define a tire
classdef tire < handleproperties carAttachedTo % I'm setting this property to the car object
%but think that may be a badthing
tireColorendmethodsfunction colorout = get.tireColor(obj)colorout = obj.carAttachedTo.paintcolorOfCar ;end
Best Answer