Re: Mixing OO and DB

From: topmind <>
Date: Mon, 25 Feb 2008 13:21:58 -0800 (PST)
Message-ID: <>

Robert Martin wrote:
> On 2008-02-22 17:41:58 -0600, topmind <> said:
> >> Actually, I think you have already named some examples. Using a dummy
> >> database for testing, for example. Not that you MUST use OO for these
> >> things; but often you can, and often it is convenient.
> >
> > Well, I think that is stretching the definition of OOP a bit far,
> > almost like saying word-processors are OOP/polymorphic because they
> > can open any document of a given extension. That's all the test DB is
> > like: we simply point the app to a different (test) DB just like a
> > word-processor or Excel opening a different document.
> Actually, I think there's a fundamental difference. In the word
> processor there is a if/else or switch statment that hands control off
> to the appropriate file parser. It goes one way for a .doc and another
> way for a .rtf. That's not an OO concept.

No. I am NOT talking about a different "kind" of database. It uses the same brand, just a different data set using the same schema as the production system.

By the way, ODBC already does what you say, more or less. One can use a CSV text file or a spreadsheet or MS-Access all using the same ODBC api/conventions. But, each database engine is different with different capabilities and operators such that they are not 100% swapcompatible.  (Text files and spreadsheets etc. usually use a generic SQL engine provided by Microsoft since they have no SQL engine of their own.) Polymorphism can't magically add features that a subtype cannot support.

(Whether ODBC uses OOP internally or not is not an app developer's concern.)

> On the other hand, when you substitute a dummy database for a real
> database, there is no if/else or switch statement that routes flow of
> control differently. The application does not know that a dummy
> database is in use. That is much closer to an OO concept.
> Now, if we take that one step further, and swap in a dummy database
> engine, and have the application access it through a polymorphic
> interface, we have true OO.

The goal in this particular scenario is to test the app. What you are trying to acheive by going OO-crazy here, I don't know.

> --
> Robert C. Martin (Uncle Bob)��| email:
> Object Mentor Inc.� � � � � ��| blog:��

-T- Received on Mon Feb 25 2008 - 22:21:58 CET

Original text of this message