MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Creating Objects

  • To: mathgroup at
  • Subject: [mg31651] RE: Creating Objects
  • From: Oleg Burd <OBurd at>
  • Date: Fri, 23 Nov 2001 05:46:21 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Thanks for a tip.
I'm realisng that Mathematica was not designed for OOP.
I hope however by using the OOP concepts to increase the reuseability of the
programs and make maintenance and reviews eaiser.
After looking in Net and FAQ's for solution I've found the package
"Classes.m" form Roman Maeder. This package makes possible to implement the
OOP in Mathematica.
I still have however problems by replicating my Model.
With Classes.m one can create Object Account:

Class[Account, Object, {bal}, {{new, (new[super]; bal = #1) &}, {balance, 
      bal &}, {deposit, Function[bal += #1]}, {withdraw, 
      Function[bal -= #1]}, {delete, (If[bal != 0, 
            Print["Remaining balance:", bal]];
          delete[super]) &}}] 

I need however not only Account, but Object  which is List of varibale
lenght of Accounts. 

  AccountSet, Object, Array[Account, n], n,
    {new, (new[super]; (Table[Account[i] = new[Account, #2], {i, n}]); 
          n = #1) &},
    {balance, Table[balance[Account[i], {i, n}]]}

It doesn't work however.
May be smbd. knows how to implement new object which is list of other
Thans all.

> -----Original Message-----
> From:	Ersek, Ted R [SMTP:ErsekTR at]
To: mathgroup at
> Sent:	Monday, November 19, 2001 2:47 PM
> To:	'mathgroup at'; 'OBurd at'
> Subject:	Re: Creating Objects
> Oleg wanted to know how to do OOP in Mathematica.
> Mathematica is not an Object Oriented Programming language.  You can
> download a package posted at 
> which will allow you to emulate OOP in Mathematica, but I doubt this is a
> good approach to Mathematica programming. Mathematica does have a powerful
> and elegant programming language that is probably not like anything you
> ever
> worked with before.  I should mention that Mathematica does support
> procedural programming constructs that are typical of other programming
> languages, but that is seldom the best way to do things in Mathematica.
> What you should do is get a good intro Mathematica book.  I will send
> another message soon recommending one in particular.
> Once you have a working knowledge of Mathematica you might find my website
> (URL below) a helpful resource.
> -----------
> Regards,
> Ted Ersek
>   Check Mathematica Tips, Tricks at

  • Prev by Date: Re: checking for a particular value in a matrix
  • Next by Date: Re: Creating Objects
  • Previous by thread: Re: Creating Objects
  • Next by thread: Re: Creating Objects