POV-Ray : Newsgroups : povray.off-topic : This is the sort of brokenness... : Re: This is the sort of brokenness... Server Time
6 Sep 2024 15:19:23 EDT (-0400)
  Re: This is the sort of brokenness...  
From: Darren New
Date: 18 Mar 2009 19:09:26
Message: <49c17f26$1@news.povray.org>
Warp wrote:
>   (If you use reflection to, for example, save the state of an object to
> a database to be retrieved later, haven't you kind of locked up the
> structure of that object? You can't make *any* changes whatsoever to it
> without breaking all the stored objects in the database. Doesn't sound
> very enhanceable to me.)

Actually, thinking about it, in this particular case of pushing something 
out to a database, the usual method is to use reflection to create a class 
based on the database schema, then instantiate objects and populate them 
from the database. So changing the object means changing the schema, then 
fixing the code that accesses the private variables of the resultant 
instances so as to perform the business logic.

So your code for reading the schema might say "I'll create an object when 
you read a row. That object will have a class whose name is row_xyz if the 
table is named xyz. The fields will be col_abc and col_def if there are two 
columns named abc and def. The types will map from SQL to C# (or whatever) 
like so: ...  I'll provide a routine called "load(...)" for each indexed 
key, and one called "save()" that writes the object back and "del()" that 
deletes the row from the database. You write the routines that use the 
columns as you like."

So when you reorg the database using SQL, you automatically get a new class 
without having to write all the code to generate SQL statements populated 
with the values of private variables.

You could do this with a code generator, sure, but that's all reflection 
stuff really is - using the compiler and runtime at runtime instead of just 
compile time.

>   If you trash memory, you are writing non-portable, non-standard-conforming
> code. All bets are off. If you want to write code like that

*I* don't write code like that at all. Others do, then blame me when their 
bugs break the modularity of my code, making it misbehave. See the problem?


-- 
   Darren New, San Diego CA, USA (PST)
   My fortune cookie said, "You will soon be
   unable to read this, even at arm's length."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.