I am working on the design for a new application and want to make the
program fully object oriented. I have built and used C++ classes
before, but never with a database driven application. Should classes
handle reading and writing their property data to the database table
themselves, or should they rely on an outside "DataHandler" custom
class or function specific to the application.
If I hard code specific database/table/query information into a
class's structure, it no longer become portable because it is
"bound" to database. I want to be able to reuse my classes and I
fear that writing storage routines "inside" the class definition
will render my classes less portable. How do most of you implement
class usage when class data need to be stored in databases and later
re-populated into a new instance of the class?
Example:
I want to build a ficticious object oriented program that allows the
user to enter in the year, make, and model of their favorite sports
car. Then that data is saved to a database table. The user also has the
ability to search the "cars" database table and display a list of
all previously saved cars. I also need to be able to reuse the classes
in other programs without needed to reconstruct the database and tables
used in the first program. It is possible that I may need to build
another program that deals with cars, but doesn't store the car
information in a database.
I already know I need a "Car" class, but should the Car class take
care of reading and writing to the database directly through methods I
expose? If I build-in database storage into the class I can't reuse
the class in another application without creating a database with a
"car" table. What to do???
Class: Car
Property1: Year
Property2: Make
Property3: Model
Method1: getCar(carID) <- populate object with database record data?
Method2: setCar(Year, Make, Model) <- update database record with
object data?
Hope I made my question clear enough.
Thanks in advance 9 1700 cr***********@hotmail.com wrote: I am working on the design for a new application and want to make the program fully object oriented. I have built and used C++ classes before, but never with a database driven application. Should classes handle reading and writing their property data to the database table themselves, or should they rely on an outside "DataHandler" custom class or function specific to the application.
[..]
This is not a language question, unfortunately. What you're trying
to do is to come up with a decent OO design of your model. "Class"
and "object" and "database" are language-neutral concepts. Try
posting to comp.object or to a database newsgroup. You need help
defining parts of your system and laying out relationships between
them, and C++ has really nothing to do with it. Once you figure out
all those language-neutral details, we can help you put it into C++
terms.
V
I posted this question here since I specifically want the perspective
of C/C++ programmers. Those terms may be "language-nuetral", but
unfortunately implementation DOES vary across programming platforms.
It's the sad truth that OO methodology differs depending on the
language. So I ask once again, can I get this question answered here or
not?
Regards
<cr***********@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com... I am working on the design for a new application and want to make the program fully object oriented. I have built and used C++ classes before, but never with a database driven application. Should classes handle reading and writing their property data to the database table themselves, or should they rely on an outside "DataHandler" custom class or function specific to the application.
If I hard code specific database/table/query information into a class's structure, it no longer become portable because it is "bound" to database. I want to be able to reuse my classes and I fear that writing storage routines "inside" the class definition will render my classes less portable. How do most of you implement class usage when class data need to be stored in databases and later re-populated into a new instance of the class?
[snip]
At the very least, people tend to prefer to have their classes remain
independent of the particular database product so that they could easily use
another some time in the future. It is usually considered bad practice for
your "domain" objects to depend on a particular storage mechanism. There
are a few patterns that are design to avoid that sort of problem (e.g.
"Serializer" http://www.ubilab.org/publications/p...erializer.pdf).
Of course, if your storage mechanism is highly unlikely to change, then
there's less of a reason to avoid that coupling. The comp.object newsgroup
would probably offer better suggestions.
--
David Hilsee
<cr***********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
[snip] It's the sad truth that OO methodology differs depending on the language.
[snip] Regards
yeah, right.
Don't beleive me? I'll give you an example. Coldfusion, which I realize
isn't a "formal OO language", yet is a language, boasts CFCs
(coldfusion components), which for all intents and purposes act as
objects once they are instantiated on the coldfusion server. CFCs treat
all code not contained within CFCs function bodies as contructor code.
Access to the This and Super scope are also provided in a limited
fashion. However, the biggest short coming perhaps, is that fact the
these so-called objects have no destructor!!! Let me say that again,
THERE IS NOT A DESTRUCTOR! Let's see you try to implement that as a
standard OO class model!
So, as I was saying. The OO methodology depends entirely on the on the
language and its complience with OO standards.
Cheers cr***********@hotmail.com wrote: Don't beleive me? I'll give you an example. Coldfusion, which I realize isn't a "formal OO language", yet is a language, boasts CFCs (coldfusion components), which for all intents and purposes act as objects once they are instantiated on the coldfusion server. CFCs treat all code not contained within CFCs function bodies as contructor code. Access to the This and Super scope are also provided in a limited fashion. However, the biggest short coming perhaps, is that fact the these so-called objects have no destructor!!! Let me say that again, THERE IS NOT A DESTRUCTOR! Let's see you try to implement that as a standard OO class model!
So, as I was saying. The OO methodology depends entirely on the on the language and its complience with OO standards.
To some extent, but it's hard to see how a C++ answer to the question you've
asked would differ in any significant way from the language-neutral answer
you'd get in an OO design course. If what you say is true then general OO
design books and courses that include example designs wouldn't even be
possible without specifying the language they are designed for.
DW
>Should classes handle reading and writing their property data to the database >table themselves, or should they rely on an outside "DataHandler" >custom class or function specific to the application.
If I hard code specific database/table/query information into a
class's structure, it no longer become portable because it is
"bound" to database. I want to be able to reuse my classes and I
what about my idea?
Your class (car etc,) will have a function Serialize(CStream *), where
CStream class will be used as stream class to read / write data.
make a stream base Class CStream, and its derived class for file
operation, CFileStream, for database operation CDatabaseStream etc.
These stream classes should support >>,<< so that Serialize() function
can read/write data through just >>, << operators.
upashu2 wrote: Should classes handle reading and writing their property data to the database >table themselves, or should they rely on an outside "DataHandler" >custom class or function specific to the application.
If I hard code specific database/table/query information into a class's structure, it no longer become portable because it is "bound" to database. I want to be able to reuse my classes and I what about my idea?
Your class (car etc,) will have a function Serialize(CStream *), where CStream class will be used as stream class to read / write data. make a stream base Class CStream, and its derived class for file operation, CFileStream, for database operation CDatabaseStream etc. These stream classes should support >>,<< so that Serialize() function can read/write data through just >>, << operators.
Good idea, but I would ditch the 'C' on all the class names. http://www.jelovic.com/articles/stupid_naming.htm
DW
I understand what you are saying about OO being taught as
language-nuetral and shouldn't be tied to a specific language. I feel
the theories taught in OO design are "mostly" practical, but many of
them are unfortunately tied to the environemnt you are designing in.
For example, in relational database thoery, there is a concept of 5th
normal form, maybe even higher. Can you image how inefficient designing
an actual database that conforms to 5th normal form would be? Even the
most seasoned DBAs typically only built relationships in databases to
conform up to 3rd normal form only. My point is merely that OO design,
like relational database theory, work flawlessly in a language-nuetral
way in textbooks, but real life experience in multiple languages has
taught me otherwise.
Cheers This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fernando Rodriguez |
last post by:
Hi,
I need to traverse the methods defined in a class and its superclasses. This
is the code I'm using:
# An instance of class B should be able to check all the methods defined in B
#and A,...
|
by: E G |
last post by:
Hi!
I am having problems in designing a class. First, I have a base class
that allocates a 3D data set and allows some other mathematical
operations with it, something like this:
template...
|
by: Leslaw Bieniasz |
last post by:
Cracow, 16.09.2004
Hi,
I have a problem with compiling the following construction involving
cross-calls of class template methods, with additional inheritance.
I want to have three class...
|
by: Lord Labakudas |
last post by:
Hi,
I have a very simple question. Is int a predefined class in the
standard C++ library. If yes, is it typedef'd as int somewhere ? I
wish to know this because, I wish to create a class that...
|
by: Jay Douglas |
last post by:
Hello, I am needing to pass a class object (this) by reference to a method
in a different class. When I do the following code I get the error (Cannot
pass '<this>' as a ref or out argument because...
|
by: Baris |
last post by:
Given the C# code below, can anyone think of a better class design? What
really gets my goat is that the code within derived classes D1 and D2 is
identical and in my mind should be refactored into...
|
by: David Lozzi |
last post by:
Howdy,
I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user...
|
by: tshad |
last post by:
I have a problem with a VS 2003 project.
This project was designed and works fine in VS 2003.
But trying to open the project I get the following error....
|
by: tshad |
last post by:
In VS 2003, I am setting up an abstract class that is setting up classes for
each datatype of VB.Net (as well as C#).
I am trying to set it up so that most of the work is done in the Abstract...
|
by: tshad |
last post by:
Using VS 2003, I am trying to take a class that I created to create new
variable types to handle nulls and track changes to standard variable types.
This is for use with database variables. This...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |