473,574 Members | 3,206 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OO DB question

I had a OO model worked out which involved forms populating new instances of
a class and being stored in an ArrayList. I'm now moving this over to a DB
backend rather than a file - I've been wondering if I even need to create
objects now? Could I just work directly with the DB e.g. form data will pass
directly to db handled in click events, the listview of objects can be read
straight from db (no need to instantiate classes).
I guess I'm after opinions on what others would do in these circumstances.
Would it be ok to interact directly with the DB, or should I use the class
instances as interfaces to the DB through their properties? Would this mean
I'd just instantiate a class to pass data to and from DB and then dispose of
it? Or keep one instance of each class to act as an interface?

Any opinions would be appreciated,

Chris

Ps Merry Christmas
Dec 25 '05 #1
8 1548
"Chris" <mi*********@mi sterjingo.com> wrote in message
news:In******** ***********@fe2 .news.blueyonde r.co.uk...
I had a OO model worked out which involved forms populating new instances
of a class and being stored in an ArrayList. I'm now moving this over to a
DB backend rather than a file - I've been wondering if I even need to
create objects now? Could I just work directly with the DB e.g. form data
will pass directly to db handled in click events, the listview of objects
can be read straight from db (no need to instantiate classes).
I guess I'm after opinions on what others would do in these circumstances.
Would it be ok to interact directly with the DB, or should I use the class
instances as interfaces to the DB through their properties? Would this
mean I'd just instantiate a class to pass data to and from DB and then
dispose of it? Or keep one instance of each class to act as an interface?

Any opinions would be appreciated,

Chris

Ps Merry Christmas


Just to clarify, when I say create objects, I originally had objects for
each form (a diary page) which stored all the text and options. This was
placed in an ArrayList and output to a file on saving.

Chris
Dec 25 '05 #2
"Chris" <mi*********@gm ail.com> a écrit dans le message de news:
Pw************* *****@fe3.news. blueyonder.co.u k...

| >I had a OO model worked out which involved forms populating new instances
| >of a class and being stored in an ArrayList. I'm now moving this over to
a
| >DB backend rather than a file - I've been wondering if I even need to
| >create objects now? Could I just work directly with the DB e.g. form data
| >will pass directly to db handled in click events, the listview of objects
| >can be read straight from db (no need to instantiate classes).
| > I guess I'm after opinions on what others would do in these
circumstances.
| > Would it be ok to interact directly with the DB, or should I use the
class
| > instances as interfaces to the DB through their properties? Would this
| > mean I'd just instantiate a class to pass data to and from DB and then
| > dispose of it? Or keep one instance of each class to act as an
interface?
| >
| > Any opinions would be appreciated,
| >
| > Chris
| >
| > Ps Merry Christmas
| >
|
| Just to clarify, when I say create objects, I originally had objects for
| each form (a diary page) which stored all the text and options. This was
| placed in an ArrayList and output to a file on saving.

Whether you are using a file or a database to store your objects, you will
still need to manage your object's lifetimes. At the moment I presume you
are loading all your objects from the file at the start of the application
and then saving them back at the end; this is similar to the Prevayler
approach.

We have designed an Object Persistence Framework. This allows us to write
code to store and retrieve objects, regardless of the ultimate storage
mechanism. Our framework is primarily concerned with using an SQL database
but the beauty of designing an OPF is that we could read objects in from a
text or XML file and then write them back out to an SQL database, or vice
versa.

Typical client code looks like :

{
Customer c = new Customer();
c.Name = "Joanna";
// set other properties

PersistenceBrok er.StoreObject( c);

Criteria crit = new EqualsCriteria< Order>("Custome r", c);

List<Order> orders = PersistenceBrok er.RetrieveList <Order>(crit) ;
...

}

From the client side, there is nothing to say what is being used for
storage, but the Broker could well have more than one data storage
Connection and you would maintain a register that records which Connection
is responsibel for storing which types of objects.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 25 '05 #3
"Joanna Carter [TeamB]" <jo****@not.for .spam> a écrit dans le message de
news: Om************* @TK2MSFTNGP15.p hx.gbl...

And I still didn't really answer your question.

There really isn't anything that allows you to retrieve objects directly
froma database, which is why I mentioned the OPF idea. A database is not
modelled on tha same paradigm as an object model; the database uses a
relational model which is subtly different from an object model.

e.g.

database :

OrderLine
- ID: integer
- OrderID: integer
- Quantity: integer
- ProductID: integer
- UnitPrice: float
- Total: float

Order
- ID: integer
- Ref: string
- Date: DateTime
- CustomerID: integer
- Total: float

object model :

OrderLine
- ID: integer
- Quantity: integer
- Product: Product
- UnitPrice: float
- Total: float

Order
- ID: integer
- Ref: string
- Date: DateTime
- Customer: Customer
- Lines: List<OrderLine>
- Total: float

Notice that in the relational model, the Order table has no knowledge of the
OrderLine table but the OrderLine table has to have a foreign key field to
link its records to a particular record in the Order Table; there may be
additional referential integrity constraints and things like cascade
deletion to ensure that when an Order is deleted, all its Lines are also
deleted.

Using an OO approach, we can dispense with the foreign key from the Line to
the Order as the Order already knows about its Lines; in fact, there really
is no need for the Line to know about the Order, as in the relational model.
Notice also that we do not use integer IDs to link object together, but
instead real references to real objects.

It is this "impedance mismatch" between the relational model and the object
model that is resolved in an OPF. A mapping hierarchy lets us specify the
relational foreign key field links without polluting the object model. In
fact all a relational database behind an OPF has to do is simple single
table selects, updates and deletes, most of the time, as all the integrity
between objects is taken care of in the business object layer.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 25 '05 #4
It's really an architectural question. Is the project small enough to manage
without an object model? for simple apps, you can pass datasets back and
forth. Definitely the easiest way to go. But this approach won't work in
more complex apps--multiple forms and numerous capabilities lead to
duplication and brittleness--when I fix X, I break Y. An object model helps
organize the work and isolate the various parts of the system from each
other, while not impeding communication among them. So, the question
becomes, "How much infrastructure do I need in this particular app?" For a
simple app, an object model is overkill.
Dec 27 '05 #5

"David Veeneman" <da****@nospam. com> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl...
It's really an architectural question. Is the project small enough to
manage without an object model? for simple apps, you can pass datasets
back and forth. Definitely the easiest way to go. But this approach won't
work in more complex apps--multiple forms and numerous capabilities lead
to duplication and brittleness--when I fix X, I break Y. An object model
helps organize the work and isolate the various parts of the system from
each other, while not impeding communication among them. So, the question
becomes, "How much infrastructure do I need in this particular app?" For a
simple app, an object model is overkill.


The app itself has 1 main form with a listview. Three types of journal can
be generated, each journal is a separate form with 5-20+ items of user input
being saved to a respective class.
Instances of these objects are stored in a List<T>, and information from
them is stored in the listview. The listview can be double clicked to edit
selected items (buttons and menus create this functionality too), items can
also be deleted in this manner. The items in list view can be sorted on a
number of criteria (dates, word search, journal type) and a combo box allows
the display of specific item types only in the listView. Other data
structures store wordlists used to colour specific words found in a journal
text body.
All the data contained in the journals in processed in a variety of ways to
produce a number of statistics.

The above is the main functionality of the application. The application
should store hundreds/thousands of journal entries at a minimum.

I thought that holding so many objects (some with large bodies of data in a
rtf form) in memory would make the application a huge memory hog, and
interfacing with a DB could possibly draw off only the items needed e.g.
listview will search the DB and draw the information it needs only. Double
clicking an item will cause the rest of the selected journal to be drawn
from the database and used to populate a form for editing etc.

Chris

Dec 27 '05 #6
"David Veeneman" <da****@nospam. com> a écrit dans le message de news:
u4************* *@TK2MSFTNGP09. phx.gbl...

| For a simple app, an object model is overkill.

In my experience, an object model is never overkill; simple apps just need
simple object models.

I have seen too many apps start out as "just a quick little app" using
controls hooked up directly to database tables. Soon, just like Topsie, it
growed and growed; until it was an absolute monster of convoluted event
driven code on forms.

My advice is : Keep it simple, but design classes before you even look at
how you are going to store instances of those classes. It really does work
out better, even for small apps; sometimes, you can even get away with
XML-type storage; then when you decide to change to a proper database, all
your business logic will remain untouched, the only thing to chaznge will be
the storage layer code.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 27 '05 #7
Hi Joanna,

Thankyou for the detailed reply. I'm still digesting what you've written,
so I'll reply with any questions soon :).

Chris
"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:OR******** ******@TK2MSFTN GP14.phx.gbl...
"Joanna Carter [TeamB]" <jo****@not.for .spam> a écrit dans le message de
news: Om************* @TK2MSFTNGP15.p hx.gbl...

And I still didn't really answer your question.

There really isn't anything that allows you to retrieve objects directly
froma database, which is why I mentioned the OPF idea. A database is not
modelled on tha same paradigm as an object model; the database uses a
relational model which is subtly different from an object model.

e.g.

database :

OrderLine
- ID: integer
- OrderID: integer
- Quantity: integer
- ProductID: integer
- UnitPrice: float
- Total: float

Order
- ID: integer
- Ref: string
- Date: DateTime
- CustomerID: integer
- Total: float

object model :

OrderLine
- ID: integer
- Quantity: integer
- Product: Product
- UnitPrice: float
- Total: float

Order
- ID: integer
- Ref: string
- Date: DateTime
- Customer: Customer
- Lines: List<OrderLine>
- Total: float

Notice that in the relational model, the Order table has no knowledge of
the
OrderLine table but the OrderLine table has to have a foreign key field to
link its records to a particular record in the Order Table; there may be
additional referential integrity constraints and things like cascade
deletion to ensure that when an Order is deleted, all its Lines are also
deleted.

Using an OO approach, we can dispense with the foreign key from the Line
to
the Order as the Order already knows about its Lines; in fact, there
really
is no need for the Line to know about the Order, as in the relational
model.
Notice also that we do not use integer IDs to link object together, but
instead real references to real objects.

It is this "impedance mismatch" between the relational model and the
object
model that is resolved in an OPF. A mapping hierarchy lets us specify the
relational foreign key field links without polluting the object model. In
fact all a relational database behind an OPF has to do is simple single
table selects, updates and deletes, most of the time, as all the integrity
between objects is taken care of in the business object layer.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 27 '05 #8
"Chris" <mi*********@gm ail.com> a écrit dans le message de news:
7s************* ******@fe3.news .blueyonder.co. uk...

| The app itself has 1 main form with a listview. Three types of journal can
| be generated, each journal is a separate form with 5-20+ items of user
input
| being saved to a respective class.
| Instances of these objects are stored in a List<T>, and information from
| them is stored in the listview. The listview can be double clicked to edit
| selected items (buttons and menus create this functionality too), items
can
| also be deleted in this manner. The items in list view can be sorted on a
| number of criteria (dates, word search, journal type) and a combo box
allows
| the display of specific item types only in the listView. Other data
| structures store wordlists used to colour specific words found in a
journal
| text body.
| All the data contained in the journals in processed in a variety of ways
to
| produce a number of statistics.
|
| The above is the main functionality of the application. The application
| should store hundreds/thousands of journal entries at a minimum.
|
| I thought that holding so many objects (some with large bodies of data in
a
| rtf form) in memory would make the application a huge memory hog, and
| interfacing with a DB could possibly draw off only the items needed e.g.
| listview will search the DB and draw the information it needs only. Double
| clicking an item will cause the rest of the selected journal to be drawn
| from the database and used to populate a form for editing etc.

You really must separate the areas of displaying, managing and storing
objects :-)

Ideally, large quantities of objects should be *stored* in a database.

How the objects are *managed* depends on quantities and other intangibles.
If you want to manage large quantities, then you would consider building a
broker which will page the objects into an in-memory list as required

*Displaying* the objects requires that your UI components will "ask" the
list for items, either on a one by one basis or a page at a time.

If you build your list class correctly, then it can surface events which can
be handled by a broker. The idea being that when the list is asked for, say,
item 45, the GetItem method would check to see if that item had already been
retrieved and, if not, would fire the ItemRequired event passing the index
required; the broker would note the index and check how many objects would
have to be retrieved to cover that index number. IT is always best to page
objects to save time, so 45 on a 10 page strategy would mean loading at
least four pages of objects.

You could also remove unused objects when they are no longer required, but
this will depend on the speed requirements of the program as to whether this
is reasonable or not.

Sorting objects that have been stored in a database and which are being
drawn into a list is usually best done by issuing SQL against the database
with a sort clause. Sorting the list means calling a Sort method on the list
class which is used to fire an event which is captured by the broker, which
will reload the list with objects sorted in the required order.

As to populating "large" objects; you are best working with partially loaded
objects for the purposes of browsing in a list, only loading all the
properties when a full object is selected for editing.

Looking at your message, it would seem like you are moving in this direction
anyway :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 28 '05 #9

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

Similar topics

1
3089
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
5019
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
2647
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask it differently. FOUR QUESTIONS: The background: I got three (3) files
3
3074
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table before rowID answID qryrow questionID datafield 1591 12 06e 06e 06e question 1593 12 06f 06f 06f question 1594 12 answer to the question 06f
10
3408
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a database or continue to process on to the next page. I am now trying to learn ASP to see if we can replace some of our applications that were written in...
10
3699
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server Error in '/QuickStartv20' Application. -------------------------------------------------------------------------------- Configuration Error...
53
4041
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
4742
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
4263
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from less to more for example). I have a question object that has two properties that contain the collections Options and Ratings. now I want this kind...
3
2542
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div class="not-required-question"><p>Question Text</p><input /></div>
0
7764
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8111
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6514
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5660
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5336
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3776
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1375
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.