Could I access to a subclass properties (values) from superclass?

8 views (last 30 days)
I want to implement the concept of hashCode on the object like Java. https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html
So, I don't know if it possible to access to all properties of subclass.
I know that I could access to public properties of the object listing with the command of properties.
I would like to extend the captabilites of Containers.Map (MATLAB) to represent a Set with objects, not only with arrays of numbers, dates, times, or text data, so implementing a hashCode with a number like Java, I think that is the correct way.
So, listing all properties of the object, and computing a hashCode with simple properties like integer, float and string or chars.
https://www.mathworks.com/help/matlab/set-operations.html

Accepted Answer

Steven Lord
Steven Lord on 13 Dec 2022
So, I don't know if it possible to access to all properties of subclass.
Superclasses should not know about the properties of their subclasses. They shouldn't depend on whether or not anyone inherits from them or how many subclasses inherit from them.
I would like to extend the captabilites of Containers.Map (MATLAB) to represent a Set with objects, not only with arrays of numbers, dates, times, or text data, so implementing a hashCode with a number like Java, I think that is the correct way.
Rather than reinventing the wheel, why not use the dictionary object introduced in release R2022b? For using custom objects with dictionary those class authors can define keyHash and keyMatch methods for those objects as shown on this documentation page.
  1 Comment
Rafa Carbonell
Rafa Carbonell on 13 Dec 2022
Thanks for your answer! Nowadays, I don't have MATLAB R2022b, but I will download it. In previous versions, dictionaries did not exist.

Sign in to comment.

More Answers (0)

Categories

Find more on Construct and Work with Object Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!