I am going to use an example to illustrate what I mean by the question title.
I would like to define a class
called namedTable
, which is essentially a table with a name. However, I would like to be able to do everything I can do to tables to this new class. For example, any function applicable to tables should apply to namedTables. Or, we should be able to access namedTable columns by using the notation namedTable.variableName
. Here is an example of the class definition and the logic I would like to make sure namedTable
inherits all functions applicable to tables:
classdef namedTable
properties
rawTable
name
end
methods
% constructor method
function obj = namedTable(T, name)
obj.rawTable = T;
obj.name = name;
end
% general inheritance of all functions applicable to tables
if fn is any fnction which can be applied to a table:
calculate fn(obj.rawTable)
if this is a table, coerce it to namedTable class by using
obj.name, and return the namedTable created.
else
output fn(obj.rawTable)
end
end
end
end
I would also have liked to use something like classdef namedTable < table
, but Matlab returns an error: Class 'table' is Sealed and may not be used as a superclass.