The point of Tangram isn't that it's "object-oriented"--the
point, I think, is that it lets you have persistent objects
w/o worrying about how to make them persistent. So rather
than you having to worry about how to structure your database
to hold a bunch of your objects, and you writing the SQL
to store them, you can concentrate on
how to use the objects, in Perl. Tangram takes care of
the storage in the database.
For example, say you have data about a bunch of people. You
know their name, their age, and their hair color. You create
a simple Perl object to hold this data, and you can instantiate
it at will:
my $me = new Person;
$me->age(22);
and so on.
Now, what if you want to make these objects persistent? In
other words, between runs of your program, you need to store
this data somewhere. A database is as good a place as any.
The problem, though, is that placing your database code
into your object (into a save method, for example)
would make your code very specific. Objects should be more
flexible about how they're stored--they shouldn't be tied
in to only one storage method.
This is where Tangram comes in: it provides the methods that
let you store your object in a database. So you can create it,
store it, quit your program, then start it up again--and
load your object from the database magically, as if it had
never left.
So it's not a matter of you being forced/cajoled/etc. into
writing object-oriented code. The point here is that you're
*already* writing OO code, and now you need a way to store
your objects. You need object persistence, and that's what
Tangram gives you.
I've never used it myself, though. :) | [reply] [d/l] |
Let me see if I got this straight...
Suppose I have an online store where I sell goods to several different countries each using its own currency. I could say (for Brazil's case):
my $real = new Currency;
$real->name('Real');
$real->country('BR');
$real->dolarValue(1.81);
And repeat this as many times necessary for each country. Then use set everything up, and use DBI to get the items from a shopping cart as usual (name, price, other attributes). Then my app would work as if my currency variables had been declared at startup, so I wouldn't have to do a 'select' myself to find out what the price of an item was in Reals?
That's a bit confusing... Let me try this instead.
Instead of doing two selects (one for the product, and one for the currency), I could have the currency loaded as an object and do my select on the product as if the currency information had always been there?
#!/home/bbq/bin/perl
# Trust no1!
| [reply] [d/l] |
Well... I'm not sure I know quite what you mean. In your
example, you could create all of those Currency objects,
then use Tangram to insert them into a database. That would
be one script.
Then, in another script, you could tell Tangram to go and
get you a particular Currency object. It would load the
data from the database and hand you back a Currency object,
just like the one you had created in the first script.
You're not actually eliminating select statements,
because *someone* still has to do a select--even if it's
not you, it's Tangram. :) But you don't have to worry about
that select; you can just act as if you had created the
Currency object in the same script.
Does that make sense?
There's a good
introduction to using Tangram
in WebTechniques.
| [reply] |