B
Big D
Hi all,
I have a general question about the best way to go about object orientation
as it relates to representing data in a database (or other source for that
matter).
Lets say I have some class "foo" that is a piece of business info. I can
populate an instance of foo (let's call it "myFoo") by sending it, let's
say, the id of a record in a database:
Dim myFoo as new Foo(433)
The new constructor goes out and gets the mess of info for this object.
This is great.
However, what if I want to make a new record of the foo type, but there are
properties of Foo that are readOnly? For example you COULD do something
like:
Dim myFoo as new Foo()
myFoo.Item1 = 3
myFoo.Item2 = 4
myFoo.insert()
and the "Insert" procedure inserts the new data into the database. But what
if myFoo.Item2 should really only be readOnly? This seems to pop up alot,
where there is a piece of information for an object that should not be
modified if it is already existing, but if you are making a new one you need
write access to it.
You can have "wrappers" for private members of the properties that are read
only so you could have something like:
Dim myFoo as New Foo()
myFoo.Item1 = 3
myFoo.ChangeItem2(4)
myFoo.Insert
or you could create a shared (static) function that returns an instance of
foo to work with like:
Dim myFoo as Foo
myFoo = Foo.CreateNewFoo(3,4)
But that seems a little wierd (?), particularly if there are a lot of items
you need to pass to create the object.
Is there a "best practice" for this sort of thing?
Thanks so much for sticking it though this long winded post!
-MC D
I have a general question about the best way to go about object orientation
as it relates to representing data in a database (or other source for that
matter).
Lets say I have some class "foo" that is a piece of business info. I can
populate an instance of foo (let's call it "myFoo") by sending it, let's
say, the id of a record in a database:
Dim myFoo as new Foo(433)
The new constructor goes out and gets the mess of info for this object.
This is great.
However, what if I want to make a new record of the foo type, but there are
properties of Foo that are readOnly? For example you COULD do something
like:
Dim myFoo as new Foo()
myFoo.Item1 = 3
myFoo.Item2 = 4
myFoo.insert()
and the "Insert" procedure inserts the new data into the database. But what
if myFoo.Item2 should really only be readOnly? This seems to pop up alot,
where there is a piece of information for an object that should not be
modified if it is already existing, but if you are making a new one you need
write access to it.
You can have "wrappers" for private members of the properties that are read
only so you could have something like:
Dim myFoo as New Foo()
myFoo.Item1 = 3
myFoo.ChangeItem2(4)
myFoo.Insert
or you could create a shared (static) function that returns an instance of
foo to work with like:
Dim myFoo as Foo
myFoo = Foo.CreateNewFoo(3,4)
But that seems a little wierd (?), particularly if there are a lot of items
you need to pass to create the object.
Is there a "best practice" for this sort of thing?
Thanks so much for sticking it though this long winded post!
-MC D