I have a class mesh1D. I want to create an another class, called crack to be the subclass of mesh1D. My subclass has one (apart from the inherited) property. What I would like to do is the following:
1) Create an instance of mesh1D, with e.g.
M = mesh1D([0 1], 10); M.generate;
2) Then create an object from the crack class:
The second one does not work. I read something, that perhaps the superclass constructor should be called, like
obj = obj@mesh1D(varargin);
But one thing I wanted to avoid with OOP is the long input argument lists the functions must provide. On the other hand, I do not understand why I have to call the superclass. I just want cr to be "part of" M, as if cr would be a structure within the M structure in functional programming.
These are my classes:
classdef mesh1D
properties
domain = [0 1];
nElem = 10;
nNode = 11;
node;
element;
connectElemNode;
end
methods
function obj = mesh1D(domain, nElem)
obj.domain = domain;
obj.nElem = nElem;
end
function obj = generate(obj)
a = obj.domain(1);
b = obj.domain(2);
gridSize = (b-a)/obj.nElem;
obj.node = [(1:obj.nElem+1)' (a:gridSize:b)'];
obj.element = [(1:obj.nElem)' (1:obj.nElem)' (2:obj.nElem+1)'];
end
end
end
classdef crack < mesh1D
properties
place;
end
methods
function obj = crack(varargin)
obj.place = crackPlace;
end
end
end
0 Comments
Sign in to comment.