I'm having a problem with reading object properties from disk.
I have three classes:
1. IMachine.cls (is an interface)
2. CMotor.cls (implements IMachine)
3. CPump.cls (implements IMachine)
General declaration:
Public Machine As IMachine
At run-time, the user can select a certain machine, resulting in
Set Machine = New CMotor
or
Set Machine = New CPump
The user can write and read the object properties to and from disk. The
properties of Machine are written to disk by using a propertybag.
But now....
When I'm reading the object properties from disk, how do I know if the
propertybag belongs to an instance of CMotor or CPump?
One way of doing this is by writing the TypeName of the instance to disk.
When reading the data from disk, you could read the TypeName first and with
an IF-THEN-construction you could create the right machine.
Is there a more refined way of doing this, especially when you have a lot
more classes than just the motor and the pump.
Geert-Pieter
> I have three classes:
> 1. IMachine.cls (is an interface)
> 2. CMotor.cls (implements IMachine)
> 3. CPump.cls (implements IMachine)
> When I'm reading the object properties from disk, how do I know if the
> propertybag belongs to an instance of CMotor or CPump?
>
> One way of doing this is by writing the TypeName of the instance to disk.
> When reading the data from disk, you could read the TypeName first and
with
> an IF-THEN-construction you could create the right machine.
>
> Is there a more refined way of doing this, especially when you have a lot
> more classes than just the motor and the pump.
Other than using a case statement for the MachineType when you create the
object, what you are doing is exactly how I would do it.
I would put a public function WhatIsThis that return a string
descriptor of the object.
**********************************************************************
Richard Jalbert Programmer-Analyst Rich...@sympatico.ca
Dog thinks: they feed me, they take care of me: they are gods.
Cat thinks: they feed me, they take care of me: I am god.
http://www3.sympatico.ca/richmann/
http://www.geocities.com/richmannsoft/
**********************************************************************