473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Database Driven Object Factory - Am I Nuts?

I'm relatively new to non trivial OOP programming and recently stumbled
across the idea of Factory classes that can create objects at runtime. I
know we can hard-code class definitions for use by our Factory classes...
just wondering if it's a common practice to drive class definitions from a
database. Somehow the possibility of doing this seems both very cool (that
it may be possible) and very dangerous ("just because you can doesn't mean
you should").

So, how would I go about automating the construction of runtime objects -
and have the definition of each object determined at runtime from a database
(in whole or in part).

Specifically (and for example) say I want to create Person objects at
runtime. Each Person has a FirstName and LastName property. Somewhere in a
database I store the fact that Person objects have a FirstName and LastName
property. Then tomorrow I want to cause Person objects to additionally have
a MiddleName property. What I want is to simply be able to update the
database and - Bingo! - the Person objects now all have a MiddleName
property.

Am I nuts or is this a reasonable thing to be attempting?

Thoughts? Opinions? Perspective on *how* Factory classes most reasonably
create runtime objects?

Thanks!
Feb 12 '06 #1
7 2544
This is actually an idea that has occured to me too and I am currently
working on a way to do this. I'd like to hear any comments on your idea.

"Jeff S" wrote:
I'm relatively new to non trivial OOP programming and recently stumbled
across the idea of Factory classes that can create objects at runtime. I
know we can hard-code class definitions for use by our Factory classes...
just wondering if it's a common practice to drive class definitions from a
database. Somehow the possibility of doing this seems both very cool (that
it may be possible) and very dangerous ("just because you can doesn't mean
you should").

So, how would I go about automating the construction of runtime objects -
and have the definition of each object determined at runtime from a database
(in whole or in part).

Specifically (and for example) say I want to create Person objects at
runtime. Each Person has a FirstName and LastName property. Somewhere in a
database I store the fact that Person objects have a FirstName and LastName
property. Then tomorrow I want to cause Person objects to additionally have
a MiddleName property. What I want is to simply be able to update the
database and - Bingo! - the Person objects now all have a MiddleName
property.

Am I nuts or is this a reasonable thing to be attempting?

Thoughts? Opinions? Perspective on *how* Factory classes most reasonably
create runtime objects?

Thanks!

Feb 12 '06 #2
Jeff,
this really all boils down to Object Relational Mapping (ORM for short).
There must be two dozen ORM frameworks out there now, many are open-source or
have free versions, and some will dynamically query your data store and do
what you are looking for.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jeff S" wrote:
I'm relatively new to non trivial OOP programming and recently stumbled
across the idea of Factory classes that can create objects at runtime. I
know we can hard-code class definitions for use by our Factory classes...
just wondering if it's a common practice to drive class definitions from a
database. Somehow the possibility of doing this seems both very cool (that
it may be possible) and very dangerous ("just because you can doesn't mean
you should").

So, how would I go about automating the construction of runtime objects -
and have the definition of each object determined at runtime from a database
(in whole or in part).

Specifically (and for example) say I want to create Person objects at
runtime. Each Person has a FirstName and LastName property. Somewhere in a
database I store the fact that Person objects have a FirstName and LastName
property. Then tomorrow I want to cause Person objects to additionally have
a MiddleName property. What I want is to simply be able to update the
database and - Bingo! - the Person objects now all have a MiddleName
property.

Am I nuts or is this a reasonable thing to be attempting?

Thoughts? Opinions? Perspective on *how* Factory classes most reasonably
create runtime objects?

Thanks!

Feb 13 '06 #3
We use a code generator that creates classes based on our database
tables.
We use SQLDMO for this. We even capture relationships between tables to
instantiate child objects.
At run time, we use reflection in our DAL to analyse our objects and
execute relevant queries.

Hope this helps.

Feb 13 '06 #4
Thanks, and yes, it helps to know this sort of thing is going on.

What has been your experience with runtime performance with reflection? It
seems that this kind of flexability would come at some price.

-J
"Steven Nagy" <le*********@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
We use a code generator that creates classes based on our database
tables.
We use SQLDMO for this. We even capture relationships between tables to
instantiate child objects.
At run time, we use reflection in our DAL to analyse our objects and
execute relevant queries.

Hope this helps.

Feb 13 '06 #5
Its not too bad really... the performance drops in other areas, such as
the multiple data queries to support nested objects and so on.
Trying to overcome this currently.

Most our projects that use this technology are windows apps, where the
database is on the same network. We have about 20-40 database hits per
second in some of our apps, and reflection seems to cope fine.

Feb 13 '06 #6
I dont use factory classes myself so apoaogies if this comes across
ignorant. But why would you want to run any objects through a databse? First
the IO innvolved for every access to create the object is going to be more
overhead, and secondly to add something such as in your example would be
just as simple, if not quicker due to no needed sql, to add to the class
itself?
"Jeff S" <A@B.COM> wrote in message
news:Om**************@TK2MSFTNGP15.phx.gbl...
I'm relatively new to non trivial OOP programming and recently stumbled
across the idea of Factory classes that can create objects at runtime. I
know we can hard-code class definitions for use by our Factory classes...
just wondering if it's a common practice to drive class definitions from a
database. Somehow the possibility of doing this seems both very cool (that
it may be possible) and very dangerous ("just because you can doesn't mean
you should").

So, how would I go about automating the construction of runtime objects -
and have the definition of each object determined at runtime from a
database (in whole or in part).

Specifically (and for example) say I want to create Person objects at
runtime. Each Person has a FirstName and LastName property. Somewhere in a
database I store the fact that Person objects have a FirstName and
LastName property. Then tomorrow I want to cause Person objects to
additionally have a MiddleName property. What I want is to simply be able
to update the database and - Bingo! - the Person objects now all have a
MiddleName property.

Am I nuts or is this a reasonable thing to be attempting?

Thoughts? Opinions? Perspective on *how* Factory classes most reasonably
create runtime objects?

Thanks!

Feb 14 '06 #7
Same argument could apply to datasets and datatables... well actually
it does.
Even MS admit the overhead involved with these classes.
However custom object factories usually run much better.
Still have to represent the data somehow, and strongly typed data is
more useful.

Feb 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Busin | last post by:
Classes B, C, D and E are derived from base class A. A* CreateB(); A* CreateC(); A* CreateD(); A* CreateE(); class X { public:
2
by: Ryan Mitchley | last post by:
Hi all I have code for an object factory, heavily based on an article by Jim Hyslop (although I've made minor modifications). The factory was working fine using g++, but since switching to the...
1
by: Gregg Altschul | last post by:
I have a Shared Object which its sole purpose is to create objects of a certain type and return a pointer to the object to the user. Therefore, the user becomes the owner of this object and is...
1
by: Dan | last post by:
All, I am working on an application that allows users to track various items for various clients. For example Client A may have an object Box where Client B has an object Canister. When a user...
6
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
22
by: amygdala | last post by:
Hi, I'm trying to grasp OOP to build an interface using class objects that lets me access database tables easily. You have probably seen this before, or maybe even built it yourself at some...
16
by: Alex | last post by:
Hello, I'm trying to use a (remote) COM object from a PHP script (4.4, server has apache2 win32). The basics seem to work : I instantiate the COM object ($o = new COM"..."), then I use two of...
0
by: dprjessie | last post by:
Hello, I am a Web programmer and I'm working on my first desktop application as a favor for a friend. I'm sure I have a stupid error here, but there is no error being thrown so I can't figure out...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.