Create Class that is both Heterogeneous and a Handle class
2 things.
1) I am looking to create a class that is both a handle class object which allows reference copies of that first object to be distributed / moved which may edit the contents of the first class object AND also be "matlab.mixin.Heterogeneous" which allows there to be an array of objects that differ in their specific class, but are all derived from one root class. In this case that I am looking for all these objects root and derived to also be handel classes.
2) I’m looking for some way to add/remove oject handles from an object’s properties dynamically. I’m not sure how this is normally handeled is Object Oriented Programming, where objects are moved between other objects like people moving form one location to another location.
For example, if I were to simulate people at a obstical course, I would have a class called People, and a root class called Locations for which there are derived classes from, like Swing, Slide, RockWall exe. In this example I want the people object to have a handle to their current location (object), and the different location classes to have a handle to what person is persent, and what location is next in the obstical course after the current one.
Alternativly, if there is maybe a better way of structuring this then I’ve mentioned I would like to know.
classdef Location < matlab.mixin.Heterogeneous %< handle ??????????? NOT SURE HOW MAKE THIS A HANDLE
% "Location" objects are able to change properties of "Person" obj and
% "Location" obj through the handles stored in this classes local properties
properties
locationID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
person (1,1) Person %handle ref, so this class may make changes to it
%next location in the obstical course:
nextLocation (1,1) Location %handle ref, so this class may make changes to it
end
methods
function movePerson(NewLocation,Person)
%find person’s prev location
prevLocation = Person.currentLocation;
%check if new Location’s person is empty
if isempty(NewLocation.person)
%set person’s prev location to empty
clear(prevLocation.person);%????????? NOT SURE HOW TO DO THIS
%Update Location’s person property
NewLocation.person = Person; %copy person handle to location obj
%Update Person’s Location property
Person.currentLocation = NewLocation; %copy location handel to person obj
end
end
end
end
classdef Swing < Location %< handle
methods
function done = sendNextLocation(Location)
if isempty(Location.nextLocation.person) %Swing objects may only accept one person at at a time
Location.AddPerson(Location.nextLocation,Location.person);
Location.RemovePerson(Location);
done = 1;
else
done = 0;
end
end
end
end
classdef Person < handle
properties
ID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
currentLocation (1,1) Location
end
end2 things.
1) I am looking to create a class that is both a handle class object which allows reference copies of that first object to be distributed / moved which may edit the contents of the first class object AND also be "matlab.mixin.Heterogeneous" which allows there to be an array of objects that differ in their specific class, but are all derived from one root class. In this case that I am looking for all these objects root and derived to also be handel classes.
2) I’m looking for some way to add/remove oject handles from an object’s properties dynamically. I’m not sure how this is normally handeled is Object Oriented Programming, where objects are moved between other objects like people moving form one location to another location.
For example, if I were to simulate people at a obstical course, I would have a class called People, and a root class called Locations for which there are derived classes from, like Swing, Slide, RockWall exe. In this example I want the people object to have a handle to their current location (object), and the different location classes to have a handle to what person is persent, and what location is next in the obstical course after the current one.
Alternativly, if there is maybe a better way of structuring this then I’ve mentioned I would like to know.
classdef Location < matlab.mixin.Heterogeneous %< handle ??????????? NOT SURE HOW MAKE THIS A HANDLE
% "Location" objects are able to change properties of "Person" obj and
% "Location" obj through the handles stored in this classes local properties
properties
locationID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
person (1,1) Person %handle ref, so this class may make changes to it
%next location in the obstical course:
nextLocation (1,1) Location %handle ref, so this class may make changes to it
end
methods
function movePerson(NewLocation,Person)
%find person’s prev location
prevLocation = Person.currentLocation;
%check if new Location’s person is empty
if isempty(NewLocation.person)
%set person’s prev location to empty
clear(prevLocation.person);%????????? NOT SURE HOW TO DO THIS
%Update Location’s person property
NewLocation.person = Person; %copy person handle to location obj
%Update Person’s Location property
Person.currentLocation = NewLocation; %copy location handel to person obj
end
end
end
end
classdef Swing < Location %< handle
methods
function done = sendNextLocation(Location)
if isempty(Location.nextLocation.person) %Swing objects may only accept one person at at a time
Location.AddPerson(Location.nextLocation,Location.person);
Location.RemovePerson(Location);
done = 1;
else
done = 0;
end
end
end
end
classdef Person < handle
properties
ID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
currentLocation (1,1) Location
end
end 2 things.
1) I am looking to create a class that is both a handle class object which allows reference copies of that first object to be distributed / moved which may edit the contents of the first class object AND also be "matlab.mixin.Heterogeneous" which allows there to be an array of objects that differ in their specific class, but are all derived from one root class. In this case that I am looking for all these objects root and derived to also be handel classes.
2) I’m looking for some way to add/remove oject handles from an object’s properties dynamically. I’m not sure how this is normally handeled is Object Oriented Programming, where objects are moved between other objects like people moving form one location to another location.
For example, if I were to simulate people at a obstical course, I would have a class called People, and a root class called Locations for which there are derived classes from, like Swing, Slide, RockWall exe. In this example I want the people object to have a handle to their current location (object), and the different location classes to have a handle to what person is persent, and what location is next in the obstical course after the current one.
Alternativly, if there is maybe a better way of structuring this then I’ve mentioned I would like to know.
classdef Location < matlab.mixin.Heterogeneous %< handle ??????????? NOT SURE HOW MAKE THIS A HANDLE
% "Location" objects are able to change properties of "Person" obj and
% "Location" obj through the handles stored in this classes local properties
properties
locationID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
person (1,1) Person %handle ref, so this class may make changes to it
%next location in the obstical course:
nextLocation (1,1) Location %handle ref, so this class may make changes to it
end
methods
function movePerson(NewLocation,Person)
%find person’s prev location
prevLocation = Person.currentLocation;
%check if new Location’s person is empty
if isempty(NewLocation.person)
%set person’s prev location to empty
clear(prevLocation.person);%????????? NOT SURE HOW TO DO THIS
%Update Location’s person property
NewLocation.person = Person; %copy person handle to location obj
%Update Person’s Location property
Person.currentLocation = NewLocation; %copy location handel to person obj
end
end
end
end
classdef Swing < Location %< handle
methods
function done = sendNextLocation(Location)
if isempty(Location.nextLocation.person) %Swing objects may only accept one person at at a time
Location.AddPerson(Location.nextLocation,Location.person);
Location.RemovePerson(Location);
done = 1;
else
done = 0;
end
end
end
end
classdef Person < handle
properties
ID (1,1) uint16 {mustBeInteger,mustBePositive} = 1
currentLocation (1,1) Location
end
end class, handles MATLAB Answers — New Questions