STORABLE - correcting object mismatch 
Author Message
 STORABLE - correcting object mismatch

I added new attributes to a class that inherits STORABLE.
Trying to retrieve from a file containing objects created from older
version of this class causes an exception -- "Retrieval error"

How do I retrieve objects from file and correct them so that they are
consistent with the modified class?

Compiler: ISE EiffelBench 4.5

Thanks.

Manvinder.



Mon, 22 Mar 2004 03:26:33 GMT  
 STORABLE - correcting object mismatch

Quote:

> I added new attributes to a class that inherits STORABLE.
> Trying to retrieve from a file containing objects created from older
> version of this class causes an exception -- "Retrieval error"

> How do I retrieve objects from file and correct them so that they are
> consistent with the modified class?

> Compiler: ISE EiffelBench 4.5

Suppose your original class is called OLD, and your new class (with extra
attributes) is called NEW.

Add a creation procedure to class NEW, with the following signature:

   make_from_old(old: OLD)

Its purpose is to initialize the attributes of a NEW object from the
values of the attributes of an OLD object.

Retrieve your stored OLD objects, then create an instance of NEW by
passing an instance of OLD to the creation feature 'make_from_old'.

Regards,
Roger
--

19 Eden Park Lancaster LA1 4SJ UK - Phone +44 1524 32428



Mon, 22 Mar 2004 04:29:43 GMT  
 STORABLE - correcting object mismatch

Quote:

> Suppose your original class is called OLD, and your new class (with extra
> attributes) is called NEW.

> Add a creation procedure to class NEW, with the following signature:

>    make_from_old(old: OLD)

> Its purpose is to initialize the attributes of a NEW object from the
> values of the attributes of an OLD object.

> Retrieve your stored OLD objects, then create an instance of NEW by
> passing an instance of OLD to the creation feature 'make_from_old'.

> Regards,
> Roger

Roger,
Thanks for the response, but changes are not restricted to a single
class. Infact, quite a few classes depending on OLD need extra
attributes.

This approach will create many classes - NEW1, NEW2, ... Can we avoid
creating NEW.. classes?

Mr.Bertrand Meyer discussed this issue in OOSC -- feature
`correct_mismatch' of class GENERAL (which could be inherited by
modified classes). But GENERAL doesn't contain any such feature???

Can u give me some suggestions/tips on these lines?

Regards,
Manvinder.



Tue, 23 Mar 2004 01:33:24 GMT  
 STORABLE - correcting object mismatch

Quote:


> > I added new attributes to a class that inherits STORABLE.
> > Trying to retrieve from a file containing objects created from older
> > version of this class causes an exception -- "Retrieval error"

> > How do I retrieve objects from file and correct them so that they are
> > consistent with the modified class?

> > Compiler: ISE EiffelBench 4.5

> Suppose your original class is called OLD, and your new class (with extra
> attributes) is called NEW.

> Add a creation procedure to class NEW, with the following signature:

>    make_from_old(old: OLD)

> Its purpose is to initialize the attributes of a NEW object from the
> values of the attributes of an OLD object.

> Retrieve your stored OLD objects, then create an instance of NEW by
> passing an instance of OLD to the creation feature 'make_from_old'.

> Regards,
> Roger

Roger, doesn't this force an undesirable renaming of the class that's
edited? Is  there a solution that avoids this?

Greg



Tue, 23 Mar 2004 06:24:36 GMT  
 STORABLE - correcting object mismatch

Quote:

> > > I added new attributes to a class that inherits STORABLE.
> > > Trying to retrieve from a file containing objects created from older
> > > version of this class causes an exception -- "Retrieval error"

> > Add a creation procedure to class NEW, with the following signature:
> >    make_from_old(old: OLD)
> > ...
> > Retrieve your stored OLD objects, then create an instance of NEW by
> > passing an instance of OLD to the creation feature 'make_from_old'.

> Roger, doesn't this force an undesirable renaming of the class that's
> edited?

It's really just Meyer's open-closed principle. You "freeze" the
definition of each storable class as soon as you have any stored
instances of it. Then, if you add some attributes to a storable type, you
write a new class that inherits from the original type and can be built
from the original type. This solution forces the application (rather than
the compiler) to deal with the evolution of stored objects, but is quite
workable.

Quote:
> Is there a solution that avoids this?

Sure, there are several. For example, the compiler could just adopt a
policy that all unstored fields are initialized to default values. Then,
there would be no problem restoring an object and attaching it to an
entity of a type that has additional attributes. But the class invariant
will fail if the additional fields are required to have non-default
values.

An alternative solution would change the whole storable mechanism so that
instead of storing attributes of an object, it stores arguments to a
creation procedure. That way, class OLD would need to be equipped with a
creation feature such as 'make_from_old' in the above example (although
we'd probably give it a name like 'restore'). Then, if class NEW inherits
from OLD it also inherits the 'restore' procedure and can automatically
restore OLD objects if we name 'restore' as a creation procedure. We'd
probably do something like this:

   class NEW
   inherit OLD
      rename restore as restore_from_old end
   creation
      restore, restore_from_old
   feature
      restore is ...
      store is ... -- store the arguments to 'restore'
      ...
   end

But writing this manually is hard work, compared to just letting the
compiler write out and read back the attributes.

Regards,
Roger
--

19 Eden Park Lancaster LA1 4SJ UK - Phone +44 1524 32428



Wed, 24 Mar 2004 03:48:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Correct way of invoking an object inside an ole object

2. An Example Using class STORABLE

3. class STORABLE in Eiffel 3.2

4. Storable,Create,Exceptions

5. Again STORABLE ...

6. Class STORABLE in PEfW

7. Storable file format for a Store Browser

8. How to use STORABLE?

9. Problems with STORABLE and C-packages

10. class STORABLE, violation of software reusabilty principle

11. STORABLE - how does it work?

12. Storable and Environment

 

 
Powered by phpBB® Forum Software