method[arg] is determined according to specific DownValues for a specific
"arg" or a general pattern for objects with the Head (or other
characteristics) of "arg". The same function or method name can be used
for many objects and classes of objects without confusion. That behavior
is, I would say, inherently object-oriented.
The opposite of object oriented is when function names must include class
names, such as integerAdd[1, 2] rather than simply 1 + 2.
Judge for yourself whether the following is simpler than the OP's code,
but I don't believe it requires mimicking C++ so closely!
methods = {index, polynomial, stiffness, mass, damping, TF,
unitStepResponse, bodePlot, poles, display};
ClearAll @@ methods
plantList = {};
plant[stiff_, damp_, m_] :=
Block[{s, t}, Module[{tf, poly, self = plant[1 + Length@plantList]},
polynomial@self = 1/(m*s^2 + damp*s + stiff);
index@self = First@self;
stiffness@self = stiff;
mass@self = m;
damping@self = damp;
tf = TransferFunctionModel[polynomial@self, s];
TF@self = tf;
unitStepResponse@self =
Chop@First@OutputResponse[tf, UnitStep[t], t];
bodePlot@self = BodePlot@tf;
poles@self = TransferFunctionPoles@tf;
AppendTo[plantList, self];
self
]]
display[any_plant] := Through[(methods[[;; -2]])@any];
new = plant[1, 1, 10];
display@new
Bobby
On Sat, 07 Apr 2012 03:34:34 -0500, Andrzej Kozlowski
<
akozl...@gmail.com> wrote:
> While I completely agree with the sentiment expressed in the second
> line, I don't think the first one is true, at least not in any sense of
> "object-oriented" I am familiar with.
>
> Andrzej
--
DrMaj...@yahoo.com