Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Begginer Question - Database 1

Status
Not open for further replies.

hoojar

Programmer
May 26, 2005
14
0
0
GB
Hi,

I'm trying to learn C# and OO. I normally use PHP/MYSQL and have dabbled with vb.net.

my question is, can I still use relational databases with OO or do I need to learn a new design method for my db's as well? and if I can use a relational DB how do i get from my DB design to my class design?

thanks.
 
>my question is, can I still use relational databases with OO
Yes. As databases are normalized to 3rd normal form, the data is naturally grouped for functionality. Like accounts recievable, customers, suppliers, accounts payable, employees and so on.

>and if I can use a relational DB how do i get from my DB design to my class design?

User Interface
^^^^^^^^^^^^^^^^^^^
Object Oriented Fuctionality
^^^^^^^^^^^^^^^^^^^
Normalized Database

Your OO Functionality should "naturally" sit upon the underlying data...


Good Luck
 
thanks vb5prgrmr, its a releif to know that.

so for example, in my DB if I have several tables making up an employee such as address, jobrole_details, logon_details, etc would they be one class each or would they be all pulled together into one class?
 
relational databases to OOP... research the concept of ORM Object Relational Mapper. This type of framework is responsible for transforming relational data into business objects (which usually contain behavior).

php has PEAR, if I recall correctly. in .net the leading ORM is NHibernate (OSS). Castle.ActiveRecord (OSS) also exists for .net. If you have a small budget you may also want to consider LLBL Gen Pro ($).

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
True OO... each would be a class/object with another object sitting on top if one wanted to say review all such pertinent data...

Just a side note of warning. With OO it is very easy to build objects upon objects on top of more objects which could lead to object confusion. So care should be taken when designing yor objects.


Good Luck

 
With OO it is very easy to build objects upon objects on top of more objects which could lead to object confusion.
this is a dangerous statement. the system needs to be flexible enough to fulfill the requirements, but no over complicated. Finding this balance is an art. The best guiding principles I found are the SOLID design patterns. thread678-1549983

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
>Dangerous statement?

Dangerous Outcome! If one is not careful. Just a fact of life in the OO world.
 
The Relational Database Model fits in very well with Object Oriented Design. Infact that is exactly what OOP technology is all about - grouping common functionality into classes which usually sit on top of a relational database engine. In multi-tier systems, this would usually be the middle tier that would communicate with the database and then pass data to the front end of the system.
 
Infact that is exactly what OOP technology is all about - grouping common functionality into classes which usually sit on top of a relational database engine.
grouping common functionality; yes. whether an application uses a db or not is irrelevant.
The Relational Database Model fits in very well with Object Oriented Design.
quite the contrary. Have to seen complexity of ORM frameworks? This is the very problem they solve. objects contain behavior, databases contain data. getting the 2 to play nice, from scratch, is no easy task.

now if you treat your objects as tables then yes there is a 1:1 mapping. But if that is the case you would save time using the DataSet concept/objects in the .net framework.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
arcdogl said:
how do i get from my DB design to my class design?
Unless you are in the unfortunate position of already having a database, you don't. Think of the database merely as a way of persisting your classes while they are not being used. The question you need to ask is "how do I get to my DB design from my class model", and as Jason has already noted there are several ORMs that will do the heavy lifting for you.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
@stevexff
well said.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
I must disagree.

In the world I live, databases exists, they cannot be changed and they're not in 3rd normal form, as it's fairly ineficient in several scenarios.

So my OO design is just for the application, from a logical or functional point of view. And after that, I'll think on the way to couple things.

Futhermore, there's no 1:1 relationship between a database and an application, so OO and database design must be independent as they will vary on their own.



Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top