BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OOP in database programming - Newbie question
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Non-Technical
View previous topic :: View next topic  
Author Message
Gary Lowe
Guest





PostPosted: Fri Jul 22, 2005 1:43 am    Post subject: OOP in database programming - Newbie question Reply with quote



Delphi 5 pro

I have no formal Delphi training, but I have written several database
programs for inventory control. Basically they track containers and what is
in them and all data is accessed through database controls.

My question is this:

Is there any advantage to creating an object representing the container,
contents and it's location, manipulating this data and then passing the data
to a routine for inclusion into the database? It seems a little redundant
to me, but I really don't know the power or possibilities of the use of OOP
in this situation.

Any help or comments are welcome. Just be patient and understand that I am
not really a programmer in the true sense of the word.

Thanks


Back to top
Lauchlan M
Guest





PostPosted: Fri Jul 22, 2005 2:45 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote



Quote:
My question is this:

Is there any advantage to creating an object representing the container,
contents and it's location, manipulating this data and then passing the
data
to a routine for inclusion into the database? It seems a little redundant
to me, but I really don't know the power or possibilities of the use of
OOP
in this situation.

Any help or comments are welcome. Just be patient and understand that I
am
not really a programmer in the true sense of the word.

Hi,

what you would be discussing is object persistance frameworks (OPFs) or
Model Driven Architectures (MDAs)

I suggest if you use Win32 look at tiOPF and Instant Objects, if you use
..net there are a number of soutions (Developer Express have one) and if you
have D2005 Architect, look at ECO.

As to whether there are benefits for you, that is for you to decide. <g>

I'd experiment using object persistence frameworks with a seperate small
project and see how you feel then.

See also the Borland delphi.oodesign and
delphi.modeldrivearchitecture.general newsgroups . . .

HTH

Lauchlan M



Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Fri Jul 22, 2005 8:31 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote



"Gary Lowe" <cincylap (AT) earthlink (DOT) net> a écrit dans le message de news:
[email]42e04f32 (AT) newsgroups (DOT) borland.com[/email]...

Quote:
I have no formal Delphi training, but I have written several database
programs for inventory control. Basically they track containers and what
is
in them and all data is accessed through database controls.

Accessing data through data-aware controls is a very bad idea. You have tied
your forms to one particular type of database and all the logic that reponds
to data changes ends up being written on the forms and means that, should
you change database provider, you then have to go through all your code and
change it to accomodate the differences in database components.

Quote:
Is there any advantage to creating an object representing the container,
contents and it's location, manipulating this data and then passing the
data
to a routine for inclusion into the database? It seems a little redundant
to me, but I really don't know the power or possibilities of the use of
OOP
in this situation.

The advantage of a true OOP approach is the separation of business logic
from database code. Using an OPF means that you can change database details
without changing any of your fundamental business logic. You should not need
any business logic such as stored procedures, triggers, etc in the database
as all that sort of logic never changes and is part of the the business
layer.

By using an OPF, you then have to find somewhere else, apart from the form
to write your business logic; and this is where the business classes come
in. Connecting the components on a form to the properties of a business
object is a matter of either designing your own 'object-aware' controls (see
my articles on MVP framework, linked to in the oodesign group), or you can
use data-aware controls linked to a custom dataset class that knows how to
talk to objects instead of database tables.

Quote:
Any help or comments are welcome. Just be patient and understand that I
am
not really a programmer in the true sense of the word.

None of us were born programmers, most of us had to learn Smile)

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Dave White
Guest





PostPosted: Fri Jul 22, 2005 8:43 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote

"Lauchlan M" <LMackinnonAT_NoSpam_ozemailDOTcomDOTau> wrote

Quote:

what you would be discussing is object persistance frameworks (OPFs) or
Model Driven Architectures (MDAs)


As a self proclaimed newbie, an OPF may be a bit adventurous at your level.
But I'd jump over to borland.public.delphi.oodesign and take a look at the
thread "
Organizing database access" from Bob Dawson that was posted in the past day
or so - this will get you started without having to go down the fully OPF
path. As Bob says, his current framewaork for object persistence extends to
almost 200 units - you need to start small

--
Dave White
SpectraChrom Software
www.spectrachrom.com

..



Back to top
David Clegg
Guest





PostPosted: Fri Jul 22, 2005 9:05 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote

I notice others have already chimed in here, but let me add that you
really should pay close attention to whatever Joanna has to say on this
subject, as she really knows her stuff here. She played a significant
part in helping me to write my first OPF.

I'd also echo the sentiment of Lauchlan and suggest checking out ECO.
It's much more than an Object Persistence Framework, but does make it
incredibly easy to separate your business objects from the persistence
mechanism. It is however only available in Delphi Architect, and is a
..NET Framework only technology.

If you are looking for a Win32 solution you could check out BOLD, which
I guess you could say is ECOs daddy. Once again, this shipped with
Delphi 7 Architect, and is available as a free download to D2005 users
(not sure whether there is any SKU restriction there).

I have also successfully used tiOPF in a Delphi 5 project. It is
actively developed, has an active mailing list, and the author (Peter
Hinrichsen) is incredibly helpful and receptive to e-mails.

--
Cheers,
David Clegg
[email]dclegg (AT) gmail (DOT) com[/email]

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 Smile
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Here's to alcohol : The cause of, and answer to all of life's
problems." - Homer Simpson
Back to top
K. Sallee
Guest





PostPosted: Fri Jul 22, 2005 9:26 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote


Quote:
Is there any advantage to creating an object representing the container

Depends on what you are doing. For a quick overview of each according to your needs, see "Summary: RAD vs. OPF" at

http://www.techinsite.com.au/tiOPF/Doc/1_WhatIsAnOPF.htm

Kevin



--

Software for resource managers and researchers
www.ecostats.com

Back to top
Edmund
Guest





PostPosted: Fri Jul 22, 2005 9:59 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote

Joanna Carter (TeamB) sighed and wrote::

Quote:

I have no formal Delphi training, but I have written several database
programs for inventory control. Basically they track containers and what
is
in them and all data is accessed through database controls.

Accessing data through data-aware controls is a very bad idea. You have tied
your forms to one particular type of database and all the logic that reponds

I don't understand this part. I'm not too fluent in Delphi and
database access in general. I'm trying to do a database app,
but it has certainly been a very steep climb.

Anyway, when you mean 'accessing data through data-aware controls is
a very bad idea', isn't that how it has always been done? I take
a datasource. a TTable. A DBGrid. Dump them on a form.
Associate a TTable with the necessary Database, and table property.
Then associate the datasource to the ttable and the dbgrid
to the datasource and boom. Activate the ttable and Bob's your
uncle.

Now that's the wrong way of doing things? I think that's what
I read in the manual (Delphi 4 Pro... so standards might have
changed, and I'm still figuring out Delphi 7's database
capabilities.

Any clarifications appreciated.

Edmund


Back to top
David Clegg
Guest





PostPosted: Fri Jul 22, 2005 10:21 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote

Edmund wrote:

Quote:
Anyway, when you mean 'accessing data through data-aware controls is
a very bad idea', isn't that how it has always been done? I take
a datasource. a TTable. A DBGrid. Dump them on a form.
Associate a TTable with the necessary Database, and table property.
Then associate the datasource to the ttable and the dbgrid
to the datasource and boom. Activate the ttable and Bob's your
uncle.

The problem with this is you then have a 'live' link to the actual data
in the database. When the values in the grid are changed, the data in
the table is updated. So if there is any validation that needs to be
done prior to posting, this can quickly degenerate into a mess of
BeforePost, AfterInsert, OnValidate etc event handlers. And of course,
all of this is embedded in the same class as your presentation logic
(the form).

IMHO, a much more maintainable approach is to seperate your business
logic into a series of logical classes modelling the actual objects
they represent (e.g. TCustomer, TInvoice, TWidget etc). This way the
presentation logic and business logic can be cleanly seperated.

Once this is done, the next step is to separate the business logic from
the persistence logic, and this is the role that an Object Persistence
Framework would normally play. So instead of calling Customer.Save,
where the Customer class may require some knowledge of how to persist
itself, you'd call DataBroker.Save(Customer). This last point is a bit
contentious (as is the whole concept, when you get right down to it),
and the way I've outlined is my preferred way of persisting objects.

Prior to going the fully fledged OPF route, I went through an
intermediary stage where I'd have the persistence logic in a
TDataModule and expose methods such as
DataModule.SaveCustomer(ACustomer: TCustomer) to handle the
persistence. This may help to cushion the impact of moving to a more
complex object oriented design, and yet still provide some benefits
over a databound control based approach.

For all the goss (and heated debates), you should check out the OO
Design groups. But be sure to Google first, as this is a topic that is
discussed often.

--
Cheers,
David Clegg
[email]dclegg (AT) gmail (DOT) com[/email]

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 Smile
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Are you sure this is the Sci-Fi Convention? It's full of nerds!" -
Homer Simpson

Back to top
Angra Mainyu
Guest





PostPosted: Fri Jul 22, 2005 10:44 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote


"David Clegg" wrote
Quote:
Edmund wrote:

Anyway, when you mean 'accessing data through data-aware controls is
a very bad idea', isn't that how it has always been done? I take
a datasource. a TTable. A DBGrid. Dump them on a form.
Associate a TTable with the necessary Database, and table property.
Then associate the datasource to the ttable and the dbgrid
to the datasource and boom. Activate the ttable and Bob's your
uncle.

The problem with this is you then have a 'live' link to the actual data
in the database. When the values in the grid are changed, the data in
the table is updated. So if there is any validation that needs to be
done prior to posting, this can quickly degenerate into a mess of
BeforePost, AfterInsert, OnValidate etc event handlers. And of course,
all of this is embedded in the same class as your presentation logic
(the form).

Get outta here! Boy, ain't you never even heard of a "disconnected" ADO
recordset being combined with the magic of a Delphi DataModule? ;)

Some may consider it slightly quick and dirty and certainly it's nowhere near as
elegant as OOP/OPF but OTOH it doesn't require science either...



Back to top
David Clegg
Guest





PostPosted: Fri Jul 22, 2005 10:53 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote

Angra Mainyu wrote:

Quote:
Get outta here! Boy, ain't you never even heard of a "disconnected"
ADO recordset being combined with the magic of a Delphi DataModule?
Wink

Heard of, but never used. :-)

I prefer to deal in terms of classes which model my problem domain,
which is why I initially liked an OPF approach, and have now migrated
to a MDA one.

However, your suggestion is definately a viable alternative, although
one which I'll have to leave the specifics up to you to suggest :-)

--
Cheers,
David Clegg
[email]dclegg (AT) gmail (DOT) com[/email]

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 Smile
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Here's to alcohol : The cause of, and answer to all of life's
problems." - Homer Simpson

Back to top
Hannes Danzl[NDD]
Guest





PostPosted: Fri Jul 22, 2005 11:40 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote

Quote:
Accessing data through data-aware controls is a very bad idea. You

IMO you should add: except you can guarantee that your application is
single user and never will be networked in any way. For single-user
applications (iow exclusive access to the db) data-aware controls are a
very nice and good thing imo.

--

Hannes Danzl [NexusDB Developer]
Newsgroup archive at http://www.tamaracka.com/search.htm

Back to top
Bob Dawson
Guest





PostPosted: Fri Jul 22, 2005 11:50 am    Post subject: Re: OOP in database programming - Newbie question Reply with quote

"Edmund" wrote
Quote:
to the datasource and boom. Activate the ttable and Bob's your
uncle.

Now that's the wrong way of doing things?

It's not a question of change (used to be right, now wrong) as a question of
where you want to go.

Using a TTable, for example--that's going to work fairly well for a single
user desktop application with a few hundred rows of data, but it's simply
not workable for a serious client-server system in which tables might
contain millions of rows. That was as true when Delphi 4 came out as it is
today.

The same might be said of direct db access--handling validation and all
other business logic in the UI and data handler events: it's going to be
quick, convenient, and entirely workable for as long as the program being
written remains simple enough for a single programmer to keep in his head.
But once things get complicated, it's simply not possible to juggle in your
head everything about (1) what you want to happen in the interface, (2) what
you want to happen from a business/domain rules perspective, and (3) what
activities need interaction with the datastore. OO techniques (and
specifically layered architectures) are approaches to separating these
concerns so you can deal with them one at a time.

So to quote our friend MS, where do you want to go today?
Straight-out-of-the-box RAD simply doesn't scale up.

bobD



Back to top
Lauchlan M
Guest





PostPosted: Fri Jul 22, 2005 12:14 pm    Post subject: Re: OOP in database programming - Newbie question Reply with quote

Quote:
Accessing data through data-aware controls is a very bad idea. You

IMO you should add: except you can guarantee that your application is
single user and never will be networked in any way. For single-user
applications (iow exclusive access to the db) data-aware controls are a
very nice and good thing imo.

Hannes,

Doesn't Joanna's point

<<
You have tied
your forms to one particular type of database and all the logic that reponds
to data changes ends up being written on the forms and means that, should
you change database provider, you then have to go through all your code and
change it to accomodate the differences in database components.
Quote:


still stand, in the single user case?

Perhaps you need to qualify further, to suggest that data aware controls
might be nice when 'you can guarantee that your application is single user
and never will be networked in any way' _and_ you are happy to remain with
one database vendor for the foreseeable future?

Lauchlan M



Back to top
Lauchlan M
Guest





PostPosted: Fri Jul 22, 2005 12:25 pm    Post subject: Re: OOP in database programming - Newbie question Reply with quote

Quote:
I have no formal Delphi training, but I have written several database
programs for inventory control. Basically they track containers and
what
is
in them and all data is accessed through database controls.

Accessing data through data-aware controls is a very bad idea. You have
tied
your forms to one particular type of database and all the logic that
reponds

I don't understand this part.

Think the difference between a TEdit and a TDBEdit. In one you enter the
data and there is no connection to the database other than a connection you
make in the code, in the other the data is tied to a database record.

With a TDBEdit, you might start handling events for BeforeEdit, AfterEdit,
BeforePost, AfterPost, etc. The code is not all centralised in one place.

If you make a clean conceptual and actual distinction between the
'presentation layer' and the 'business logic' you can use the presentation
layer just for presenting (displaying), and centralise the business logic in
a more ordered way.

Many n-tier frameworks use this approach, for example see my article
http://www.remobjects.com/articles/?id=46226804-2BBB-4D2E-92BA-C5A0204BE714
for an overview of one solution.

The discussion in this thread is about focusing on the objects, and
seperating out the layers of the objects, the data, the business logic, and
the presentation, and Joanna's points were aimed at this.

HTH

Lauchlan M



Back to top
Angra Mainyu
Guest





PostPosted: Fri Jul 22, 2005 1:17 pm    Post subject: Re: OOP in database programming - Newbie question Reply with quote


"David Clegg" wrote
Quote:
Angra Mainyu wrote:

However, your suggestion is definately a viable alternative, although
one which I'll have to leave the specifics up to you to suggest Smile

Another viable alternative is to use the Kim Madsen component set and that way
he will get to hold users hand. ;-)



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Non-Technical All times are GMT
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.