Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9561
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: fyi, small note on using Mathematica for object based programming |
| Date | 2012-04-11 22:17 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jm4vt0$2jt$1@smc.vnet.net> (permalink) |
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
<akozlowski@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
>
>
> On 6 Apr 2012, at 11:58, DrMajorBob wrote:
>
>> Mathematica is already object-oriented WITHOUT all that. What a lot of
>> overhead for nothing.
>>
>> Bobby
>>
>> On Thu, 05 Apr 2012 04:49:54 -0500, Nasser M. Abbasi <nma@12000.org>
>> wrote:
>>
>>>
>>> Just FYI,
>>>
>>> I wrote this small note on using Mathematica for object-based
>>> programming. I found that it works really well for me.
>>>
>>> Nothing too advanced, just a simple way of using Module[] but
>>> in a way to emulate object based programming that I did not know
>>> about before.
>>>
>>> http://12000.org/my_notes/object_based_in_mathematica/v1.html
>>>
>>> --Nasser
>>>
>>
>>
>> --
>> DrMajorBob@yahoo.com
>>
>
--
DrMajorBob@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: fyi, small note on using Mathematica for object based programming DrMajorBob <btreat1@austin.rr.com> - 2012-04-11 22:17 +0000
csiph-web