<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Arashid</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Arashid"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Arashid"/>
	<updated>2026-07-19T13:07:51Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16677</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16677"/>
		<updated>2008-08-01T21:51:39Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
&lt;br /&gt;
[http://www.rubyonrails.org/ ROR (Ruby-on-Rails)] has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
*''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
# '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
# '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
# '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
# Simple to implement&lt;br /&gt;
# Good for existing database with new applications&lt;br /&gt;
# Less time spend on OO modeling&lt;br /&gt;
# Good choice for simple problems&lt;br /&gt;
&lt;br /&gt;
*''' Cons ''' &lt;br /&gt;
&lt;br /&gt;
# Centered around Data Modeling&lt;br /&gt;
# Not use full capabilities of OO modeling&lt;br /&gt;
# Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
# '''Introduction'''&lt;br /&gt;
&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
* '''Framework/Library support '''&lt;br /&gt;
&lt;br /&gt;
# '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
# '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
# '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
# Supports full OO modeling approach in layered application.&lt;br /&gt;
# Allows object persistence to be easily coupled with business logic&lt;br /&gt;
# Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
# Through some framework support, it could be transparent.&lt;br /&gt;
# It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
*''' Cons '''&lt;br /&gt;
&lt;br /&gt;
# Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
# It requires layer approach for application design.&lt;br /&gt;
# Not suitable for simple solution.&lt;br /&gt;
# It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16095</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16095"/>
		<updated>2008-07-28T22:02:52Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Data Access Object (DAO) Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
*''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
# '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
# '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
# '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
# Simple to implement&lt;br /&gt;
# Good for existing database with new applications&lt;br /&gt;
# Less time spend on OO modeling&lt;br /&gt;
# Good choice for simple problems&lt;br /&gt;
&lt;br /&gt;
*''' Cons ''' &lt;br /&gt;
&lt;br /&gt;
# Centered around Data Modeling&lt;br /&gt;
# Not use full capabilities of OO modeling&lt;br /&gt;
# Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
# '''Introduction'''&lt;br /&gt;
&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
* '''Framework/Library support '''&lt;br /&gt;
&lt;br /&gt;
# '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
# '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
# '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
# Supports full OO modeling approach in layered application.&lt;br /&gt;
# Allows object persistence to be easily coupled with business logic&lt;br /&gt;
# Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
# Through some framework support, it could be transparent.&lt;br /&gt;
# It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
*''' Cons '''&lt;br /&gt;
&lt;br /&gt;
# Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
# It requires layer approach for application design.&lt;br /&gt;
# Not suitable for simple solution.&lt;br /&gt;
# It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16094</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16094"/>
		<updated>2008-07-28T22:00:39Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
*''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
# '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
# '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
# '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
# Simple to implement&lt;br /&gt;
# Good for existing database with new applications&lt;br /&gt;
# Less time spend on OO modeling&lt;br /&gt;
# Good choice for simple problems&lt;br /&gt;
&lt;br /&gt;
*''' Cons ''' &lt;br /&gt;
&lt;br /&gt;
# Centered around Data Modeling&lt;br /&gt;
# Not use full capabilities of OO modeling&lt;br /&gt;
# Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16093</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16093"/>
		<updated>2008-07-28T22:00:14Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
*''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
# '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
# '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
# '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
* Simple to implement&lt;br /&gt;
# Good for existing database with new applications&lt;br /&gt;
# Less time spend on OO modeling&lt;br /&gt;
# Good choice for simple problems&lt;br /&gt;
&lt;br /&gt;
*''' Cons ''' &lt;br /&gt;
&lt;br /&gt;
# Centered around Data Modeling&lt;br /&gt;
# Not use full capabilities of OO modeling&lt;br /&gt;
# Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16092</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16092"/>
		<updated>2008-07-28T21:59:42Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
*''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
* Simple to implement&lt;br /&gt;
# Good for existing database with new applications&lt;br /&gt;
# Less time spend on OO modeling&lt;br /&gt;
# Good choice for simple problems&lt;br /&gt;
&lt;br /&gt;
*''' Cons ''' &lt;br /&gt;
&lt;br /&gt;
# Centered around Data Modeling&lt;br /&gt;
# Not use full capabilities of OO modeling&lt;br /&gt;
# Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16091</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16091"/>
		<updated>2008-07-28T21:59:12Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
*''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
&lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
&lt;br /&gt;
*''' Cons ''' &lt;br /&gt;
&lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16090</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16090"/>
		<updated>2008-07-28T21:58:45Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
*''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
*''' Pros '''&lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
*''' Cons ''' &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16089</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16089"/>
		<updated>2008-07-28T21:58:04Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
*'''Introduction''' &lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
*'''Example''' &lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
''' Pros '''&lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
''' Cons ''' &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16088</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16088"/>
		<updated>2008-07-28T21:57:21Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Active Record Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
'''Introduction'''&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
''' Frameworks/Library support '''&lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
''' Pros '''&lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
''' Cons ''' &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16087</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16087"/>
		<updated>2008-07-28T21:55:04Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Techniques for merging Relational and OO models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
*'''Minimize the differences'''&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
*'''Compensation'''&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16086</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=16086"/>
		<updated>2008-07-28T21:54:15Z</updated>

		<summary type="html">&lt;p&gt;Arashid: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
#'''Encapsulation'''&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
#'''Data type differences'''&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
#'''Structural and integrity differences'''&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
#'''Manipulative differences'''&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
#'''Transactional differences'''&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15873</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15873"/>
		<updated>2008-07-26T22:37:13Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Frameworks/Library support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - [http://www.rubyonrails.org/ Ruby-on-Rail](ActiveRecord)&lt;br /&gt;
* '''Java''' - [https://jactiverecord.dev.java.net/ JactiveRecord], [https://jactiverecord.dev.java.net/ ARJ], [http://jroller.com/page/buggybean/20050710#activemapper_part_1_automatic_mapping ActiveMapper]&lt;br /&gt;
* '''.NET''' - [http://www.castleproject.org/ Castle Project]&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15872</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15872"/>
		<updated>2008-07-26T22:34:42Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Framework/Library support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – [http://www.hibernate.org/ Hibernate], [http://java.sun.com/javaee/technologies/persistence.jsp JPA Java JEE Persistence], [http://db.apache.org/ojb/ OJB], [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''.NET''' – [http://www.nhibernate.org/ nHibernate], [http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx LINQ],[http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
* '''Ruby''' - [http://ibatis.apache.org/ iBATIS]&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15868</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15868"/>
		<updated>2008-07-26T22:27:43Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
[http://www.hibernate.org/ Hibernate] is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The [http://www.hibernate.org/ Hibernate website] has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database.&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – Hibernate, JEE Persistence, OJB, iBATIS&lt;br /&gt;
* '''.NET''' – nHibernate, JingDAO, iBATIS&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15867</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15867"/>
		<updated>2008-07-26T22:27:17Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
Hibernate is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The Hibernate website has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – Hibernate, JEE Persistence, OJB, iBATIS&lt;br /&gt;
* '''.NET''' – nHibernate, JingDAO, iBATIS&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;br /&gt;
* http://www.hibernate.org/&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15866</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15866"/>
		<updated>2008-07-26T22:26:31Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
Hibernate is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The Hibernate website has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – Hibernate, JEE Persistence, OJB, iBATIS&lt;br /&gt;
* '''.NET''' – nHibernate, JingDAO, iBATIS&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
There are number of good solutions available in the form of design patterns to address the ORM issues. A developer has to be careful using one of those patterns. One solution based on Active Record might not be feasible on other application that involves a complex object model. Although frameworks based on these patterns are evolving and these are addressing new issues very effectively, still Object persistence is a major issue in application performance. Some languages are started evolving in this direction. Microsoft LINQ is such an example that is extended the language to solve this problem.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15865</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15865"/>
		<updated>2008-07-26T22:25:38Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Data Access Object (DAO) Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
Hibernate is a very good implementation example of DAO design pattern. It has actually gone beyond simple implementation of DAO and now supports its own query language.  It is hard to up come with some simple example in it as it requires lot of configuration steps. The Hibernate website has a [http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html  nice tutorial] to walk you through all configuration steps. I will only demo code that uses a properly setup hibernate application. &lt;br /&gt;
&lt;br /&gt;
In order to support the transparent cache and other optimizations, hibernate uses  a session . One has to get a session first to perform any CRUD operations. The following is an example of object persistence,&lt;br /&gt;
&lt;br /&gt;
    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;
&lt;br /&gt;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;
        session.beginTransaction();&lt;br /&gt;
        Event theEvent = new Event();&lt;br /&gt;
        theEvent.setTitle(title);&lt;br /&gt;
        theEvent.setDate(theDate);&lt;br /&gt;
        session.save(theEvent);&lt;br /&gt;
        session.getTransaction().commit();&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
This code stores new event to backend database. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Framework/Library support ====&lt;br /&gt;
&lt;br /&gt;
* '''Java''' – Hibernate, JEE Persistence, OJB, iBATIS&lt;br /&gt;
* '''.NET''' – nHibernate, JingDAO, iBATIS&lt;br /&gt;
&lt;br /&gt;
==== Pros ====&lt;br /&gt;
&lt;br /&gt;
* Supports full OO modeling approach in layered application.&lt;br /&gt;
* Allows object persistence to be easily coupled with business logic&lt;br /&gt;
* Hides the complexities associated with database manipulation (no SQL)&lt;br /&gt;
* Through some framework support, it could be transparent.&lt;br /&gt;
* It supports more persistence options in addition to a relational database (XML, files, Web service etc.).&lt;br /&gt;
&lt;br /&gt;
==== Cons ====&lt;br /&gt;
&lt;br /&gt;
* Hard to implement but with support of latest frameworks it is getting quite easy&lt;br /&gt;
* It requires layer approach for application design.&lt;br /&gt;
* Not suitable for simple solution.&lt;br /&gt;
* It doesn’t easily support working on existing database with complex model (with long tree of objects).&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15864</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15864"/>
		<updated>2008-07-26T22:22:15Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Data Access Object (DAO) Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
[[Image:Dataaccessobject.gif]]&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Dataaccessobject.gif&amp;diff=15863</id>
		<title>File:Dataaccessobject.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Dataaccessobject.gif&amp;diff=15863"/>
		<updated>2008-07-26T22:21:50Z</updated>

		<summary type="html">&lt;p&gt;Arashid: Data Access Object (DAO)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Data Access Object (DAO)&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15862</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15862"/>
		<updated>2008-07-26T22:21:01Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Object/Relational Mapping (ORM) Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
=== Data Access Object (DAO) Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This the second most commonly used design pattern for ORM. It actually also picks the second technique from merging OO model and relational model (Compensation). It addresses the issues that are missing from OO model related to database persistence with the help of more code. This code could come from some framework (Hibernate) or by adding some utility classes. This pattern also works will the layer approach for application development, where persistence layer is based on this pattern.&lt;br /&gt;
&lt;br /&gt;
This pattern suggests creating additional objects to encapsulate all the data access logic. DAO (Data Access Objects) are responsible for connecting to the data source (which could be a relational database or XML or web services or files) and for the retrieval of data. Most of the time this pattern also uses the TransferObject/ValueObject pattern to move data between business layer and DAO object. The following is UML diagram that relationship more clearly,&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15861</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15861"/>
		<updated>2008-07-26T22:17:52Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Object/Relational Mapping (ORM) Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
==== Frameworks/Library support ==== &lt;br /&gt;
&lt;br /&gt;
All major Object Oriented languages have some kind framework to support this pattern. Some of them are really sophisticated like the Ruby-On-Rails implementation that generates dynamic methods to support complex criteria for accessing the data.  Here are few of them,&lt;br /&gt;
&lt;br /&gt;
* '''Ruby''' - Ruby-on-Rail(ActiveRecord)&lt;br /&gt;
* '''Java''' - JactiveRecord, ARJ, ActiveMapper&lt;br /&gt;
* '''.NET''' - Castle Project&lt;br /&gt;
&lt;br /&gt;
==== Pros ==== &lt;br /&gt;
* Simple to implement&lt;br /&gt;
* Good for existing database with new applications&lt;br /&gt;
* Less time spend on OO modeling&lt;br /&gt;
* Good choice for simple problems&lt;br /&gt;
==== Cons ==== &lt;br /&gt;
* Centered around Data Modeling&lt;br /&gt;
* Not use full capabilities of OO modeling&lt;br /&gt;
* Too simple for complex models&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15860</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15860"/>
		<updated>2008-07-26T22:14:49Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Object/Relational Mapping (ORM) Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
ROR (Ruby-on-Rails) has strong support for Active Record pattern; following example shows the simplicity and power of Active Records,&lt;br /&gt;
&lt;br /&gt;
Here developer has extended a class Employee from ROR ActiveRecord class. &lt;br /&gt;
&lt;br /&gt;
  class Employee &amp;lt; ActiveRecord::Base; end&lt;br /&gt;
&lt;br /&gt;
ROR will automatically map this object to the “employee” table.&lt;br /&gt;
&lt;br /&gt;
  Create table employees(&lt;br /&gt;
    id:int,&lt;br /&gt;
    first_name varchar(100),&lt;br /&gt;
    last_name varchar(100),&lt;br /&gt;
    email varchar(100),&lt;br /&gt;
    PRIMARY KEY (id)&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
Now let’s create a new employee,&lt;br /&gt;
 &lt;br /&gt;
  employee = Employee.new(:first_name=&amp;gt; ‘Ben’, :last_name=&amp;gt;’Powel’, :email=&amp;gt; ‘ben@company.com’)&lt;br /&gt;
  employee.save&lt;br /&gt;
&lt;br /&gt;
In backend ROR framework actually created the following SQL statement to store this new employee into database,&lt;br /&gt;
&lt;br /&gt;
  insert into employee (first_name, last_name, email) values (‘Ben’, ‘Powel’, ‘ben@company.com)&lt;br /&gt;
&lt;br /&gt;
Now searching for the same object is also easy,&lt;br /&gt;
&lt;br /&gt;
  employee = Employee. find(:condition=&amp;gt; “first_name = ‘Ben’”)&lt;br /&gt;
&lt;br /&gt;
This code generate following sql statement in the backend,&lt;br /&gt;
&lt;br /&gt;
  select * from employees where first_name = ‘Ben’&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15859</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15859"/>
		<updated>2008-07-26T22:13:51Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Object/Relational Mapping (ORM) Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
This is the simplest way of accessing database through Objects. It deals the problem of ORM with second technique of merging OO Model and Relational Model (Minimize the differences).  By using a power of reflection object could find the relationship between table columns and its properties. Using code generation it adds data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
In this pattern a database table or view is wrapped into a class, thus an object actually represents a single row in the table.  A new object when persistent actually creates a new row in the table. The object has accessor methods for each column in the table and methods for CRUD operations. &lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15625</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15625"/>
		<updated>2008-07-25T16:53:35Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Object/Relational Mapping (ORM) Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
As design patterns provide number of solutions to deal with different type of challenges in software design, they also play a major role in establishing a link between database and OO model. This approach commonly refered to as ORM (Object/Relation Mapping). There are number of tools both open source and commercial available to facilitate this approach. &lt;br /&gt;
=== Active Record Pattern ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15624</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15624"/>
		<updated>2008-07-25T16:52:26Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Techniques for merging Relational and OO models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
So now we agree that relational model and OO model are totally different approaches.  So how do we built the system where these two model need to be combined? Here I will discuss high level approaches to show how to merge these two competing approaches together,&lt;br /&gt;
&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
Don’t go to that direction where these approaches separate out. Just work on those parts where these approaches agree with each other. One solution is in form of Object-Oriented Database Management Systems (OODBMS). In this approach OO model are getting special database to solve their persistence problem. Due to lack of support of data models this techniques is not widely use by the development community. Other approach is to layer your application into different concern. All latest software development is based on this approach. In this technique application is divided into multiple layers of functionality. &lt;br /&gt;
=== Compensation ===&lt;br /&gt;
In this technique developers use reflection or code generation techniques to overcome the deficiencies of each approach (Relational and Object Oriented). Using a reflection object could establish the link between table and an object’s properties.  Using this approach, the links will be stored into database (ActiveRecord). Other technique is based on code generation, where one could either by looking at relational mode generate OO model or through OO model to relation model. This also generates typical data manipulation methods (CRUD – Create, Read, Update, and Delete) to provide OO model generic data manipulation capabilities.&lt;br /&gt;
&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15623</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15623"/>
		<updated>2008-07-25T16:44:42Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Mismatches */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
OO models have the concept of encapsulation where object states are hidden from the outside world but there is no such thing in relational model. All data elements are available to every one in a relational model. &lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
Data type system is another big difference. Databases don’t support pointers where OO model embrace then on a high level. String is one example, in OO Model size of String is based on available memory but in relational databases the developer has to define the maximum allowable length. Such restrictions make it difficult for an OO model to talk with backend database system.&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
OO Models support nesting and tree like structure where as relational models are restricted to only rows and columns. Constraints on implementation are also different between relational model and OO model. &lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
Relational model has fix well define set of operation to query and manipulate the data, where OO model doesn’t have a generic operations. OO model has to define all operations at a very low level. &lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
This is the place where OO is weaker then relational model. In database if is much easier to dynamically bind data manipulation operations as units of work where as in OO model such a thing doesn’t exists.&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15622</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15622"/>
		<updated>2008-07-25T16:42:52Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Mismatches */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== 1. Encapsulation ====&lt;br /&gt;
==== 2. Data type differences ====&lt;br /&gt;
==== 3. Structural and integrity differences ====&lt;br /&gt;
==== 4. Manipulative differences ====&lt;br /&gt;
==== 5. Transactional differences ====&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15621</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15621"/>
		<updated>2008-07-25T16:41:30Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* * Encapsulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
*==== Encapsulation ====&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15620</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15620"/>
		<updated>2008-07-25T16:41:16Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Mismatches */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== * Encapsulation ====&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15619</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15619"/>
		<updated>2008-07-25T16:41:01Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Mismatches */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
==== Encapsulation ====&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15618</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15618"/>
		<updated>2008-07-25T16:40:11Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Differences between Relational Vs Object-Oriented Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example (Customer and Customer Address) ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15617</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15617"/>
		<updated>2008-07-25T16:39:01Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Differences between Relational Vs Object-Oriented Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
=== Relational Model example ===&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Object Oriented Model example ===&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15616</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15616"/>
		<updated>2008-07-25T16:38:17Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Differences between Relational Vs Object-Oriented Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
The Object-oriented models are based on the best practices of the latest software engineering principles where as relational models are based on proven mathematical principles. You find more impedance when you actually try to follow one model. In Object Oriented models, objects traverse through their relationships with other objects whereas in relational model you join rows of data. That makes them two totally different approaches. Following is an example of such two cases,&lt;br /&gt;
&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15615</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15615"/>
		<updated>2008-07-25T16:37:40Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Differences between Relational Vs Object-Oriented Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
[[Image:oomodel.gif]]&lt;br /&gt;
&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Oomodel.gif&amp;diff=15614</id>
		<title>File:Oomodel.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Oomodel.gif&amp;diff=15614"/>
		<updated>2008-07-25T16:36:14Z</updated>

		<summary type="html">&lt;p&gt;Arashid: OO Models&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;OO Models&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15612</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15612"/>
		<updated>2008-07-25T16:34:16Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Object-Oriented Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
&lt;br /&gt;
Orient-Oriented models consist of objects that have both data and behavior. They usually represent the real word better than rational models do. There are lots of general purpose object oriedned languages available to support such type of model. Now days most of development done through this approach.&lt;br /&gt;
&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15611</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15611"/>
		<updated>2008-07-25T16:33:00Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Relational Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''&amp;quot;A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.&amp;quot;''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15610</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15610"/>
		<updated>2008-07-25T16:32:31Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Relational Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say ''A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15609</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15609"/>
		<updated>2008-07-25T16:31:58Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Relational Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
This model deals with data structure and suggests the relational theory to organize it. It was proposed by Edgar Codd in 1969. It is the foundation of every modern database. It defines a logical view of data based on two concepts. &lt;br /&gt;
&lt;br /&gt;
# Domain/data type&lt;br /&gt;
# Relations&lt;br /&gt;
&lt;br /&gt;
The domain simply represents a set of values which is equivalent to data type in programming languages. A relation over the domain D1, D2, …, Dn is simply a subset of the Cartesian product; usual notation is R “include in” D1xD2x…xDn. An element of a Cartesian set is called a tuple.  So we could say &lt;br /&gt;
&lt;br /&gt;
''A database is a collection of relation valued variables, together with set of integrity constraints that the data must satisfy.''&lt;br /&gt;
&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15608</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15608"/>
		<updated>2008-07-25T16:30:36Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
This article deals with merging two software development models. Most of data are already stored in relational databases that are modeled around relational models. But all new development is being done in some Object Oriented language. Software design patterns are providing a solution in terms of ORM (Object Oriented Mapping) to merge these two models. &lt;br /&gt;
&lt;br /&gt;
In this article first I will set the stage by giving some background information about the relational model and object oriented models and their differences. After this I will briefly discuss the philosophical approaches to merge them together. By then user should have a good understanding of the problem and techniques to solve it, now it is time to show some design patterns that solve this problem in very elegant way. I will pick two major design patterns that are mostly used by development teams.&lt;br /&gt;
&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15606</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15606"/>
		<updated>2008-07-25T16:29:32Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_mapping&lt;br /&gt;
* http://www.theserverside.com/news/thread.tss?thread_id=40581&lt;br /&gt;
* http://www.objectarchitects.de/ObjectArchitects/orpatterns/orindex.htm&lt;br /&gt;
* http://martinfowler.com/eaaCatalog/&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch&lt;br /&gt;
* http://www.lhotka.net/Article.aspx?id=ff226256-903f-4aee-a921-8b09ef40901b&lt;br /&gt;
* http://en.wikipedia.org/wiki/Object-relational_database&lt;br /&gt;
* http://gilbane.com/ctoblog/2007/09/relational-and-objectoriented.html&lt;br /&gt;
* http://www.geocities.com/tablizer/core1.htm&lt;br /&gt;
* http://c2.com/cgi/wiki?RelationalModel&lt;br /&gt;
* http://www.agiledata.org/essays/impedanceMismatch.html&lt;br /&gt;
* http://en.wikipedia.org/wiki/ActiveRecord_%28Castle%29&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15597</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15597"/>
		<updated>2008-07-25T16:04:45Z</updated>

		<summary type="html">&lt;p&gt;Arashid: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
== Relational Models ==&lt;br /&gt;
== Object-Oriented Models ==&lt;br /&gt;
== Differences between Relational Vs Object-Oriented Models ==&lt;br /&gt;
[[Image:Relational.gif]]&lt;br /&gt;
=== Mismatches ===&lt;br /&gt;
== Techniques for merging Relational and OO models ==&lt;br /&gt;
=== Minimize the differences ===&lt;br /&gt;
=== Compensation ===&lt;br /&gt;
== Object/Relational Mapping (ORM) Patterns ==&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
== Links ==&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15592</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15592"/>
		<updated>2008-07-25T15:56:23Z</updated>

		<summary type="html">&lt;p&gt;Arashid: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
= Relational Vs Object-Oriented Models =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Relational.gif]]&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15371</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15371"/>
		<updated>2008-07-24T19:33:50Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
[[Image:Relational.gif]]&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Relational.gif&amp;diff=15370</id>
		<title>File:Relational.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Relational.gif&amp;diff=15370"/>
		<updated>2008-07-24T19:32:54Z</updated>

		<summary type="html">&lt;p&gt;Arashid: Relational model example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Relational model example&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15304</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15304"/>
		<updated>2008-07-24T16:30:39Z</updated>

		<summary type="html">&lt;p&gt;Arashid: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= WIKI Topic - RDB/OO patterns=&lt;br /&gt;
&lt;br /&gt;
:It would be good if OO programs could interact with OO databases, but alas, relational databases have a 99% market share. This has led to many attempts to access them from OO languages. Design patterns for doing this have been developed, starting with [http://c2.com/cgi/wiki?CrossingChasms Crossing Chasms] and extending to [http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29 Rails' ActiveRecord] [http://wiki.rubyonrails.org/rails/pages/ActiveRecord][http://ar.rubyonrails.com/]. Here, we investigate the various approaches for marrying OO programs to relational databases, comparing them in terms of ease of programming, robustness, and efficiency.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
[[Image:Example.jpg]]&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15231</id>
		<title>CSC/ECE 517 Summer 2008/wiki3 1 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki3_1_ar&amp;diff=15231"/>
		<updated>2008-07-24T03:20:33Z</updated>

		<summary type="html">&lt;p&gt;Arashid: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WIKI entry&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki2_2_ar&amp;diff=13856</id>
		<title>CSC/ECE 517 Summer 2008/wiki2 2 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki2_2_ar&amp;diff=13856"/>
		<updated>2008-06-25T18:38:07Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
This wiki entry will discusses about the importance of naming conventions and how they effect the readability of source code? It also shows examples of Java and Ruby langauge naming conventions. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
===Source code===&lt;br /&gt;
The source code is a set of computer instructions written mostly in ASCII text following some specific high level computer language syntaxes. They are human readable and need some special programs (Compilers and Interpreters) to convert it into machine languages.  They actually represent the logic of the program.&lt;br /&gt;
&lt;br /&gt;
===Problems face by source code===&lt;br /&gt;
# '''Organization of code''' - Organization of code is a difficult job. As amount and complexity increases it become harder to do that. &lt;br /&gt;
# '''Source code comprehension''' - Source code readability is actually associated with source [http://en.wikipedia.org/wiki/Program_comprehension code comprehension]. It is foundation through which a developer make sense of source code. There are some other [http://grok2.tripod.com/code_comprehension.html techniques/tools] available that support program comprehension but nothing could match with batter readable source code.&lt;br /&gt;
# '''Complex computer language syntaxes''' - Some time computer languages design with complex notations, that make those languages very powerful but it also forces programmer to stop first to understand the language constructs then follow the actual program logic.&lt;br /&gt;
&lt;br /&gt;
=Naming conventions=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Naming_convention Naming conventions] is standard way of making names of things to embed additional information. This technique is very effectively used in normal life to remove irregularities.  Numbering houses even and odd numbers across street to represent there direction on the road is an example of simple naming conventions.&lt;br /&gt;
&lt;br /&gt;
In computer languages naming convention mostly represent rules for defining different identifiers in the program. Class names, variable names, and source file names are good examples of such rules. Good naming rules increase the source code comprehension. In some modern languages (Ruby and Ruby-on-Rails) these convention even also used as configuration information.&lt;br /&gt;
&lt;br /&gt;
==Benefits of standardize naming conventions==&lt;br /&gt;
* Improve source code comprehension.&lt;br /&gt;
* Reduces the maintenance cost.&lt;br /&gt;
* Could be used as configuration information.&lt;br /&gt;
* Improves code readability.&lt;br /&gt;
* Could allow to embed metadata information with identifier names.&lt;br /&gt;
* Avoids the &amp;quot;naming collisions&amp;quot;.&lt;br /&gt;
* Reduces the requirement of program documentation&lt;br /&gt;
&lt;br /&gt;
==Factors effecting naming conventions==&lt;br /&gt;
===Language specific===&lt;br /&gt;
Readability of source code is very specific to target language. When developers move from one language to other, they start complaining about existing coding standards but later they would figure out the reason for those standards. Joel Spolky has a nice article ([http://www.joelonsoftware.com/articles/Wrong.html Making Wrong Code Look Wrong]) addressing this issue.&lt;br /&gt;
===Nature of work/domain===&lt;br /&gt;
Nature of software is also very important factor effecting naming conventions. A developer who never worked on web application development might complain about lack of comments explaining session and cookies variables but for web application developer it is common thing. &lt;br /&gt;
===Developers preferences===&lt;br /&gt;
Developers are people and as every person has different taste for clothing and food, similarly developers have opinion about different style of naming. Some developers who are coming from embedded or real-time software development might like smaller names then developers of business applications.&lt;br /&gt;
&lt;br /&gt;
==Elements of naming conventions==&lt;br /&gt;
There are number of elements that define the basics of naming conventions. They actually differentiate one naming standard from another one. These elements are influence by the factors we discussed in last section. &lt;br /&gt;
===Length of identifiers===&lt;br /&gt;
This element is part of big debate both in professional and academic circles, what is good, brevity or expressiveness? Some standards recommend fixed size names, some don’t allow abbreviations, some ask to add specific characters to define the type of identifier (like use of I to represent interface classes etc.).&lt;br /&gt;
===Letter case and numerals===&lt;br /&gt;
Some conventions have rules about case of letters according to there types (Like first Uppercase letter for class names and first lowercase letter for method names) and some use no restriction on letters case but add numbers or special characters to identifies the type of identifiers (Like in ruby @ use for public variables etc.)&lt;br /&gt;
===Word boundaries===&lt;br /&gt;
For multiple words most of languages do not allow whitespaces in identifier names. Some recommend using underscore (“_”) character as separator or use of [http://en.wikipedia.org/wiki/CamelCase CamelCase]. CamelCase technique uses uppercase letter to define the word boundaries. For example,&lt;br /&gt;
 EmployeeType&lt;br /&gt;
 &lt;br /&gt;
 addOrder	&lt;br /&gt;
CamelCase works most of time but with acronym it procedures bad names like DaoEmploye.&lt;br /&gt;
&lt;br /&gt;
=General naming conventions=&lt;br /&gt;
There are few naming conventions that are not specific to any language but include the basic principles of program languages. In these conventions naming of identifies not only reflects the domain but also platform specific types too. &lt;br /&gt;
==Hungarian notations==&lt;br /&gt;
This is a well-known naming convention that incorporates purpose or type of identity with its name. Examples,&lt;br /&gt;
&lt;br /&gt;
 IEmployeeType // Interface name&lt;br /&gt;
 &lt;br /&gt;
 btnSubmit // Submit Button &lt;br /&gt;
 &lt;br /&gt;
 arrEmployees // employees array&lt;br /&gt;
 &lt;br /&gt;
 strUsername // user name in string&lt;br /&gt;
&lt;br /&gt;
==Positional notations==&lt;br /&gt;
This convention mostly used in mainframe and COBOL environment where system usually has limitation on numbers of character use for identifier names. A typical scheme is something like, two characters for application name, three characters for module or process name in that application and rest is numbers to make them unique. &lt;br /&gt;
&lt;br /&gt;
 OPCAT001 // OP - Order processing, CAT - Catalog, 001 - first variable&lt;br /&gt;
&lt;br /&gt;
=Language specific naming conventions=&lt;br /&gt;
==Java==&lt;br /&gt;
Sun has a very comprehensive guideline for [http://java.sun.com/docs/codeconv/ Java source coding]. It includes everything from source code organization to naming classes. It is difficult to include everything here. I am going to just specify the naming convention for basic things,&lt;br /&gt;
&lt;br /&gt;
===Packages===&lt;br /&gt;
Prefix of package names is always in all lowercase. It is also recommended to start the package names from top-level domain names i.e., com, edu, org, mil, net. Examples, &lt;br /&gt;
&lt;br /&gt;
 com.sun.lang, edu.ncsu.csc517.pg&lt;br /&gt;
&lt;br /&gt;
===Classes=== &lt;br /&gt;
Class names should be nouns and starting character should be capital. If name requires any division, then use mixed case where every starting character is capital. Examples, &lt;br /&gt;
&lt;br /&gt;
 class Employee&lt;br /&gt;
 &lt;br /&gt;
 class GraduateStudent.&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
&lt;br /&gt;
Names for interfaces should also follow the class name conventions. Examples, &lt;br /&gt;
&lt;br /&gt;
 interface DataAccessObject&lt;br /&gt;
 &lt;br /&gt;
 interface StudyType.&lt;br /&gt;
&lt;br /&gt;
===Method Names===&lt;br /&gt;
Method names should start with some verb and first letter is in lowercase. Examples, &lt;br /&gt;
&lt;br /&gt;
 runApp()&lt;br /&gt;
 &lt;br /&gt;
 addCustomerOrderInformation&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
Variable names also follow method naming rules. Examples, &lt;br /&gt;
&lt;br /&gt;
 studentId&lt;br /&gt;
 &lt;br /&gt;
 employeeName&lt;br /&gt;
&lt;br /&gt;
===Constants=== &lt;br /&gt;
Class constants and ANSI standard constant should be all upper case separated by underscores (“_”). Examples, &lt;br /&gt;
&lt;br /&gt;
 EMPLOYEE_MAX_AGE&lt;br /&gt;
 &lt;br /&gt;
 WINDOW_WIDTH&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
Most of the time, Ruby and Ruby-on-Rails follow the same naming convention like Java. But there are a few differences. One more thing we should be careful about Ruby and Ruby-on-Rails is, since they follow convention over configuration schema, some naming rules are more important for successful execution of application. &lt;br /&gt;
&lt;br /&gt;
=== Local variables===&lt;br /&gt;
All lowercase letters are separated by underscores. Examples: &lt;br /&gt;
&lt;br /&gt;
 employee_age&lt;br /&gt;
&lt;br /&gt;
If it is starts with a capital letter then it is a constant. Example &lt;br /&gt;
&lt;br /&gt;
 Constant=10&lt;br /&gt;
&lt;br /&gt;
===Instance variables===&lt;br /&gt;
Starts with single “at” sign (@) follow by name. It is suggested to have all lowercase for variable name after @ sign. Examples,&lt;br /&gt;
&lt;br /&gt;
 @name&lt;br /&gt;
 &lt;br /&gt;
 @address&lt;br /&gt;
&lt;br /&gt;
===Instance Method===&lt;br /&gt;
Starts with lowercase letter follow by digits, underscores and letters. Examples, &lt;br /&gt;
&lt;br /&gt;
 paint_door&lt;br /&gt;
 &lt;br /&gt;
 manager?.&lt;br /&gt;
&lt;br /&gt;
===Class variables===&lt;br /&gt;
Starts with double “at” signs (@@) and followed by letters, digits, and underscores. Examples,&lt;br /&gt;
&lt;br /&gt;
 @@employee&lt;br /&gt;
&lt;br /&gt;
===Constants=== &lt;br /&gt;
Starts with an upper case letter followed by other characters. Sometimes, developers use all upper case names for constant. Examples,&lt;br /&gt;
&lt;br /&gt;
 PI&lt;br /&gt;
 &lt;br /&gt;
 MAX_AGE.&lt;br /&gt;
&lt;br /&gt;
===Class and Modules===&lt;br /&gt;
Class and module names start with uppercase. Examples, &lt;br /&gt;
&lt;br /&gt;
 Class Employee&lt;br /&gt;
 &lt;br /&gt;
 module DatabaseFunctions.&lt;br /&gt;
&lt;br /&gt;
===Global variables===&lt;br /&gt;
Starts with dollar ($) sign and followed by characters. Examples, &lt;br /&gt;
&lt;br /&gt;
 $company&lt;br /&gt;
&lt;br /&gt;
=Tools=&lt;br /&gt;
&lt;br /&gt;
Developing naming conventions is a smaller job then actually making sure those rules are being followed by the team. Luckily there are few tools available that make this task easier. I have used [http://checkstyle.sourceforge.net CheckStyle] on my job and it worked beautifully. Checkstyle is a fully configurable development tool that makes sure that code is following proper naming conventions. It has integration available with all well known development environments. I have included few links to tutorials using checkstyle in Eclipse and Netbeans in links section.&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
Cost of software development keeps increasing and especially maintenance cost is hurting lot of in-production applications. Major contributor to high cost is associated with difficulty to understand the existing code. A lot of time documentation is not synchronized with code updates. In those cases the importance of code readability increases even more. Having proper naming conventions not only improves the development time but it also reduces the cost of maintenance.&lt;br /&gt;
&lt;br /&gt;
Establishing naming convention is very tricky area. It should not be develop in isolation. Team’s developers’ suggestion should also consider besides looking at industry standards. All successful open source projects start with proper naming conventions. I have included few links, in case someone need some examples.&lt;br /&gt;
&lt;br /&gt;
=Links=&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/CamelCase CamelCase]&lt;br /&gt;
* [http://www.wikihow.com/Improve-the-Readability-of-Your-Software-Code How to Improve the Readability of your software code]&lt;br /&gt;
* [http://csdl2.computer.org/persagen/DLAbsToc.jsp?resourcePath=/dl/mags/co/&amp;amp;toc=comp/mags/co/1995/08/r8toc.xml&amp;amp;DOI=10.1109/2.402076 Program Comprehension During Software Maintenance and Evolution]&lt;br /&gt;
* [http://www.perlmonks.org/?node_id=592616 What is code readability?]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Source_code Source Code]&lt;br /&gt;
* [http://www.javalobby.org/java/forums/t96280.html Does &amp;quot;code readability&amp;quot; mean different things to different people?]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Naming_convention Naming convention]&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/ms229045.aspx .NET General Naming Conventions]&lt;br /&gt;
==Coding conventions for languages==&lt;br /&gt;
*ActionScript(Flex): [http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions Flex SDK coding conventions and best practices]&lt;br /&gt;
*C++: [http://en.wikibooks.org/wiki/C%2B%2B_Programming/Code_Style C++ Programming/Code Style]&lt;br /&gt;
*C++: [http://geosoft.no/development/cppstyle.html GeoSoft's C++ Programming Style Guidelines]&lt;br /&gt;
*C#: [http://www.tiobe.com/standards/gemrcsharpcs.pdf Coding Standard: C# (Philips Medical Systems)]&lt;br /&gt;
*D: [http://www.digitalmars.com/d/1.0/dstyle.html The D Style]&lt;br /&gt;
*Erlang: [http://www.erlang.se/doc/programming_rules.shtml Erlang Programming Rules and Conventions]&lt;br /&gt;
*Java: [http://java.sun.com/docs/codeconv/ Sun official Java coding style]&lt;br /&gt;
*Lisp: [http://mumble.net/~campbell/scheme/style.txt Riastradh's Lisp Style Rules]&lt;br /&gt;
*Mono: [http://www.mono-project.com/Coding_Guidelines Programming style for Mono] &lt;br /&gt;
*Perl: [http://perldoc.perl.org/perlstyle.html Perl Style Guide] &lt;br /&gt;
*PHP::PEAR: [http://pear.php.net/manual/en/standards.php PHP::PEAR Coding Standards]&lt;br /&gt;
*Python: [http://www.python.org/peps/pep-0008.html Style Guide for Python Code]&lt;br /&gt;
*Ruby: [http://itsignals.cascadia.com.au/?p=7 Ruby and Rails Naming Conventions]&lt;br /&gt;
==Coding conventions for projects==&lt;br /&gt;
*[http://httpd.apache.org/dev/styleguide.html Apache Developers' C Language Style Guide] &lt;br /&gt;
*[http://lxr.linux.no/source/Documentation/CodingStyle Linux Kernel Coding Style] &lt;br /&gt;
*[http://www.mozilla.org/hacking/mozilla-style-guide.html Mozilla Coding Style Guide] &lt;br /&gt;
*[ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/share/misc/style The NetBSD source code style guide (formerly known as the BSD Kernel Normal Form)]&lt;br /&gt;
==CheckStyle==&lt;br /&gt;
*[http://checkstyle.sourceforge.net/ CheckStyle project website]&lt;br /&gt;
*[http://blogs.sun.com/geertjan/entry/checkstyle CheckStyle with Netbeans]&lt;br /&gt;
*[http://www.testearly.com/2007/06/06/agile-developers-toolbox-checkstyle-for-eclipse/ CheckStyle with Eclipse]&lt;br /&gt;
*[http://eclipse-cs.sourceforge.net/ Checkstyle plugin for Eclipse]&lt;br /&gt;
*[http://javaboutique.internet.com/reviews/checkstyle/ Good tutorial with some background]&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki2_2_ar&amp;diff=13854</id>
		<title>CSC/ECE 517 Summer 2008/wiki2 2 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki2_2_ar&amp;diff=13854"/>
		<updated>2008-06-25T18:34:21Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
This wiki entry will discusses about the importance of naming conventions and how they effect the readability of source code? It also shows examples of Java and Ruby langauge naming conventions. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
===Source code===&lt;br /&gt;
The source code is a set of computer instructions written mostly in ASCII text following some specific high level computer language syntaxes. They are human readable and need some special programs (Compilers and Interpreters) to convert it into machine languages.  They actually represent the logic of the program.&lt;br /&gt;
&lt;br /&gt;
===Problems face by source code===&lt;br /&gt;
# '''Organization of code''' - Organization of code is a difficult job. As amount and complexity increases it become harder to do that. &lt;br /&gt;
# '''Source code comprehension''' - Source code readability is actually associated with source [http://en.wikipedia.org/wiki/Program_comprehension code comprehension]. It is foundation through which a developer make sense of source code. There are some other [http://grok2.tripod.com/code_comprehension.html techniques/tools] available that support program comprehension but nothing could match with batter readable source code.&lt;br /&gt;
# '''Complex computer language syntaxes''' - Some time computer languages design with complex notations, that make those languages very powerful but it also forces programmer to stop first to understand the language constructs then follow the actual program logic.&lt;br /&gt;
&lt;br /&gt;
=Naming conventions=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Naming_convention Naming conventions] is standard way of making names of things to embed additional information. This technique is very effectively used in normal life to remove irregularities.  Numbering houses even and odd numbers across street to represent there direction on the road is an example of simple naming conventions.&lt;br /&gt;
&lt;br /&gt;
In computer languages naming convention mostly represent rules for defining different identifiers in the program. Class names, variable names, and source file names are good examples of such rules. Good naming rules increase the source code comprehension. In some modern languages (Ruby and Ruby-on-Rails) these convention even also used as configuration information.&lt;br /&gt;
&lt;br /&gt;
==Benefits of standardize naming conventions==&lt;br /&gt;
* Improve source code comprehension.&lt;br /&gt;
* Reduces the maintenance cost.&lt;br /&gt;
* Could be used as configuration information.&lt;br /&gt;
* Improves code readability.&lt;br /&gt;
* Could allow to embed metadata information with identifier names.&lt;br /&gt;
* Avoids the &amp;quot;naming collisions&amp;quot;.&lt;br /&gt;
* Reduces the requirement of program documentation&lt;br /&gt;
&lt;br /&gt;
==Factors effecting naming conventions==&lt;br /&gt;
===Language specific===&lt;br /&gt;
Readability of source code is very specific to target language. When developers move from one language to other, they start complaining about existing coding standards but later they would figure out the reason for those standards. Joel Spolky has a nice article ([http://www.joelonsoftware.com/articles/Wrong.html Making Wrong Code Look Wrong]) addressing this issue.&lt;br /&gt;
===Nature of work/domain===&lt;br /&gt;
Nature of software is also very important factor effecting naming conventions. A developer who never worked on web application development might complain about lack of comments explaining session and cookies variables but for web application developer it is common thing. &lt;br /&gt;
===Developers preferences===&lt;br /&gt;
Developers are people and as every person has different taste for clothing and food, similarly developers have opinion about different style of naming. Some developers who are coming from embedded or real-time software development might like smaller names then developers of business applications.&lt;br /&gt;
&lt;br /&gt;
==Elements of naming conventions==&lt;br /&gt;
There are number of elements that define the basics of naming conventions. They actually differentiate one naming standard from another one. These elements are influence by the factors we discussed in last section. &lt;br /&gt;
===Length of identifiers===&lt;br /&gt;
This element is part of big debate both in professional and academic circles, what is good, brevity or expressiveness? Some standards recommend fixed size names, some don’t allow abbreviations, some ask to add specific characters to define the type of identifier (like use of I to represent interface classes etc.).&lt;br /&gt;
===Letter case and numerals===&lt;br /&gt;
Some conventions have rules about case of letters according to there types (Like first Uppercase letter for class names and first lowercase letter for method names) and some use no restriction on letters case but add numbers or special characters to identifies the type of identifiers (Like in ruby @ use for public variables etc.)&lt;br /&gt;
===Word boundaries===&lt;br /&gt;
For multiple words most of languages do not allow whitespaces in identifier names. Some recommend using underscore (“_”) character as separator or use of [http://en.wikipedia.org/wiki/CamelCase CamelCase]. CamelCase technique uses uppercase letter to define the word boundaries. For example,&lt;br /&gt;
 EmployeeType&lt;br /&gt;
 &lt;br /&gt;
 addOrder	&lt;br /&gt;
CamelCase works most of time but with acronym it procedures bad names like DaoEmploye.&lt;br /&gt;
&lt;br /&gt;
=General naming conventions=&lt;br /&gt;
There are few naming conventions that are not specific to any language but include the basic principles of program languages. In these conventions naming of identifies not only reflects the domain but also platform specific types too. &lt;br /&gt;
==Hungarian notations==&lt;br /&gt;
This is a well-known naming convention that incorporates purpose or type of identity with its name. Examples,&lt;br /&gt;
&lt;br /&gt;
 IEmployeeType // Interface name&lt;br /&gt;
 &lt;br /&gt;
 btnSubmit // Submit Button &lt;br /&gt;
 &lt;br /&gt;
 arrEmployees // employees array&lt;br /&gt;
 &lt;br /&gt;
 strUsername // user name in string&lt;br /&gt;
&lt;br /&gt;
==Positional notations==&lt;br /&gt;
This convention mostly used in mainframe and COBOL environment where system usually has limitation on numbers of character use for identifier names. A typical scheme is something like, two characters for application name, three characters for module or process name in that application and rest is numbers to make them unique. &lt;br /&gt;
&lt;br /&gt;
 OPCAT001 // OP - Order processing, CAT - Catalog, 001 - first variable&lt;br /&gt;
&lt;br /&gt;
=Language specific naming conventions=&lt;br /&gt;
==Java==&lt;br /&gt;
Sun has a very comprehensive guideline for [http://java.sun.com/docs/codeconv/ Java source coding]. It includes everything from source code organization to naming classes. It is difficult to include everything here. I am going to just specify the naming convention for basic things,&lt;br /&gt;
&lt;br /&gt;
===Packages===&lt;br /&gt;
Prefix of package names is always in all lowercase. It is also recommended to start the package names from top-level domain names i.e., com, edu, org, mil, net. Examples, &lt;br /&gt;
&lt;br /&gt;
 com.sun.lang, edu.ncsu.csc517.pg&lt;br /&gt;
&lt;br /&gt;
===Classes=== &lt;br /&gt;
Class names should be nouns and starting character should be capital. If name requires any division, then use mixed case where every starting character is capital. Examples, &lt;br /&gt;
&lt;br /&gt;
 class Employee&lt;br /&gt;
 &lt;br /&gt;
 class GraduateStudent.&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
&lt;br /&gt;
Names for interfaces should also follow the class name conventions. Examples, &lt;br /&gt;
&lt;br /&gt;
 interface DataAccessObject&lt;br /&gt;
 &lt;br /&gt;
 interface StudyType.&lt;br /&gt;
&lt;br /&gt;
===Method Names===&lt;br /&gt;
Method names should start with some verb and first letter is in lowercase. Examples, &lt;br /&gt;
&lt;br /&gt;
 runApp()&lt;br /&gt;
 &lt;br /&gt;
 addCustomerOrderInformation&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
Variable names also follow method naming rules. Examples, &lt;br /&gt;
&lt;br /&gt;
 studentId&lt;br /&gt;
 &lt;br /&gt;
 employeeName&lt;br /&gt;
&lt;br /&gt;
===Constants=== &lt;br /&gt;
Class constants and ANSI standard constant should be all upper case separated by underscores (“_”). Examples, &lt;br /&gt;
&lt;br /&gt;
 EMPLOYEE_MAX_AGE&lt;br /&gt;
 &lt;br /&gt;
 WINDOW_WIDTH&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
Most of the time, Ruby and Ruby-on-Rails follow the same naming convention like Java. But there are a few differences. One more thing we should be careful about Ruby and Ruby-on-Rails is, since they follow convention over configuration schema, some naming rules are more important for successful execution of application. &lt;br /&gt;
&lt;br /&gt;
=== Local variables===&lt;br /&gt;
All lowercase letters are separated by underscores. Examples: &lt;br /&gt;
&lt;br /&gt;
 employee_age&lt;br /&gt;
&lt;br /&gt;
If it is starts with a capital letter then it is a constant. Example &lt;br /&gt;
&lt;br /&gt;
 Constant=10&lt;br /&gt;
&lt;br /&gt;
===Instance variables===&lt;br /&gt;
Starts with single “at” sign (@) follow by name. It is suggested to have all lowercase for variable name after @ sign. Examples,&lt;br /&gt;
&lt;br /&gt;
 @name&lt;br /&gt;
 &lt;br /&gt;
 @address&lt;br /&gt;
&lt;br /&gt;
===Instance Method===&lt;br /&gt;
Starts with lowercase letter follow by digits, underscores and letters. Examples, &lt;br /&gt;
&lt;br /&gt;
 paint_door&lt;br /&gt;
 &lt;br /&gt;
 manager?.&lt;br /&gt;
&lt;br /&gt;
===Class variables===&lt;br /&gt;
Starts with double “at” signs (@@) and followed by letters, digits, and underscores. Examples,&lt;br /&gt;
&lt;br /&gt;
 @@employee&lt;br /&gt;
&lt;br /&gt;
===Constants=== &lt;br /&gt;
Starts with an upper case letter followed by other characters. Sometimes, developers use all upper case names for constant. Examples,&lt;br /&gt;
&lt;br /&gt;
 PI&lt;br /&gt;
 &lt;br /&gt;
 MAX_AGE.&lt;br /&gt;
&lt;br /&gt;
===Class and Modules===&lt;br /&gt;
Class and module names start with uppercase. Examples, &lt;br /&gt;
&lt;br /&gt;
 Class Employee&lt;br /&gt;
 &lt;br /&gt;
 module DatabaseFunctions.&lt;br /&gt;
&lt;br /&gt;
===Global variables===&lt;br /&gt;
Starts with dollar ($) sign and followed by characters. Examples, &lt;br /&gt;
&lt;br /&gt;
 $company&lt;br /&gt;
&lt;br /&gt;
=Tools=&lt;br /&gt;
&lt;br /&gt;
Developing naming conventions is a smaller job then actually making sure those rules are being followed by the team. Luckily there are few tools available that make this task easier. I have used [http://checkstyle.sourceforge.net CheckStyle] on my job and it worked beautifully. Checkstyle is a fully configurable development tool that makes sure that code is following proper naming conventions. It has integration available with all well known development environments. I have included few links to tutorials using checkstyle in Eclipse and Netbeans in links section.&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
Cost of software development keeps increasing and especially maintenance cost is hurting lot of in-production applications. Major contributor to high cost is associated with difficulty to understand the existing code. A lot of time documentation is not synchronized with code updates. In those cases the importance of code readability increases even more. Having proper naming conventions not only improves the development time but it also reduces the cost of maintenance.&lt;br /&gt;
&lt;br /&gt;
Establishing naming convention is very tricky area. It should not be develop in isolation. Team’s developers’ suggestion should also consider besides looking at industry standards. All successful open source projects start with proper naming conventions. I have included few links, in case someone need some examples.&lt;br /&gt;
&lt;br /&gt;
=Links=&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/CamelCase CamelCase]&lt;br /&gt;
* [http://www.wikihow.com/Improve-the-Readability-of-Your-Software-Code How to Improve the Readability of your software code]&lt;br /&gt;
* [http://csdl2.computer.org/persagen/DLAbsToc.jsp?resourcePath=/dl/mags/co/&amp;amp;toc=comp/mags/co/1995/08/r8toc.xml&amp;amp;DOI=10.1109/2.402076 Program Comprehension During Software Maintenance and Evolution]&lt;br /&gt;
==Coding conventions for languages==&lt;br /&gt;
*ActionScript(Flex): [http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions Flex SDK coding conventions and best practices]&lt;br /&gt;
*C++: [http://en.wikibooks.org/wiki/C%2B%2B_Programming/Code_Style C++ Programming/Code Style]&lt;br /&gt;
*C++: [http://geosoft.no/development/cppstyle.html GeoSoft's C++ Programming Style Guidelines]&lt;br /&gt;
*C#: [http://www.tiobe.com/standards/gemrcsharpcs.pdf Coding Standard: C# (Philips Medical Systems)]&lt;br /&gt;
*D: [http://www.digitalmars.com/d/1.0/dstyle.html The D Style]&lt;br /&gt;
*Erlang: [http://www.erlang.se/doc/programming_rules.shtml Erlang Programming Rules and Conventions]&lt;br /&gt;
*Java: [http://java.sun.com/docs/codeconv/ Sun official Java coding style]&lt;br /&gt;
*Lisp: [http://mumble.net/~campbell/scheme/style.txt Riastradh's Lisp Style Rules]&lt;br /&gt;
*Mono: [http://www.mono-project.com/Coding_Guidelines Programming style for Mono] &lt;br /&gt;
*Perl: [http://perldoc.perl.org/perlstyle.html Perl Style Guide] &lt;br /&gt;
*PHP::PEAR: [http://pear.php.net/manual/en/standards.php PHP::PEAR Coding Standards]&lt;br /&gt;
*Python: [http://www.python.org/peps/pep-0008.html Style Guide for Python Code]&lt;br /&gt;
*Ruby: [http://itsignals.cascadia.com.au/?p=7 Ruby and Rails Naming Conventions]&lt;br /&gt;
==Coding conventions for projects==&lt;br /&gt;
*[http://httpd.apache.org/dev/styleguide.html Apache Developers' C Language Style Guide] &lt;br /&gt;
*[http://lxr.linux.no/source/Documentation/CodingStyle Linux Kernel Coding Style] &lt;br /&gt;
*[http://www.mozilla.org/hacking/mozilla-style-guide.html Mozilla Coding Style Guide] &lt;br /&gt;
*[ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/share/misc/style The NetBSD source code style guide (formerly known as the BSD Kernel Normal Form)]&lt;br /&gt;
==CheckStyle==&lt;br /&gt;
*[http://checkstyle.sourceforge.net/ CheckStyle project website]&lt;br /&gt;
*[http://blogs.sun.com/geertjan/entry/checkstyle CheckStyle with Netbeans]&lt;br /&gt;
*[http://www.testearly.com/2007/06/06/agile-developers-toolbox-checkstyle-for-eclipse/ CheckStyle with Eclipse]&lt;br /&gt;
*[http://eclipse-cs.sourceforge.net/ Checkstyle plugin for Eclipse]&lt;br /&gt;
*[http://javaboutique.internet.com/reviews/checkstyle/ Good tutorial with some background]&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki2_2_ar&amp;diff=13853</id>
		<title>CSC/ECE 517 Summer 2008/wiki2 2 ar</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Summer_2008/wiki2_2_ar&amp;diff=13853"/>
		<updated>2008-06-25T18:32:14Z</updated>

		<summary type="html">&lt;p&gt;Arashid: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
This wiki entry will discusses about the importance of naming conventions and how they effect the readability of source code? It also shows examples of Java and Ruby langauge naming conventions. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
===Source code===&lt;br /&gt;
The source code is a set of computer instructions written mostly in ASCII text following some specific high level computer language syntaxes. They are human readable and need some special programs (Compilers and Interpreters) to convert it into machine languages.  They actually represent the logic of the program.&lt;br /&gt;
&lt;br /&gt;
===Problems face by source code===&lt;br /&gt;
# '''Organization of code''' - Organization of code is a difficult job. As amount and complexity increases it become harder to do that. &lt;br /&gt;
# '''Source code comprehension''' - Source code readability is actually associated with source [http://en.wikipedia.org/wiki/Program_comprehension code comprehension]. It is foundation through which a developer make sense of source code. There are some other [http://grok2.tripod.com/code_comprehension.html techniques/tools] available that support program comprehension but nothing could match with batter readable source code.&lt;br /&gt;
# '''Complex computer language syntaxes''' - Some time computer languages design with complex notations, that make those languages very powerful but it also forces programmer to stop first to understand the language constructs then follow the actual program logic.&lt;br /&gt;
&lt;br /&gt;
=Naming conventions=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Naming_convention Naming conventions] is standard way of making names of things to embed additional information. This technique is very effectively used in normal life to remove irregularities.  Numbering houses even and odd numbers across street to represent there direction on the road is an example of simple naming conventions.&lt;br /&gt;
&lt;br /&gt;
In computer languages naming convention mostly represent rules for defining different identifiers in the program. Class names, variable names, and source file names are good examples of such rules. Good naming rules increase the source code comprehension. In some modern languages (Ruby and Ruby-on-Rails) these convention even also used as configuration information.&lt;br /&gt;
&lt;br /&gt;
==Benefits of standardize naming conventions==&lt;br /&gt;
* Improve source code comprehension.&lt;br /&gt;
* Reduces the maintenance cost.&lt;br /&gt;
* Could be used as configuration information.&lt;br /&gt;
* Improves code readability.&lt;br /&gt;
* Could allow to embed metadata information with identifier names.&lt;br /&gt;
* Avoids the &amp;quot;naming collisions&amp;quot;.&lt;br /&gt;
* Reduces the requirement of program documentation&lt;br /&gt;
&lt;br /&gt;
==Factors effecting naming conventions==&lt;br /&gt;
===Language specific===&lt;br /&gt;
Readability of source code is very specific to target language. When developers move from one language to other, they start complaining about existing coding standards but later they would figure out the reason for those standards. Joel Spolky has a nice article ([http://www.joelonsoftware.com/articles/Wrong.html Making Wrong Code Look Wrong]) addressing this issue.&lt;br /&gt;
===Nature of work/domain===&lt;br /&gt;
Nature of software is also very important factor effecting naming conventions. A developer who never worked on web application development might complain about lack of comments explaining session and cookies variables but for web application developer it is common thing. &lt;br /&gt;
===Developers preferences===&lt;br /&gt;
Developers are people and as every person has different taste for clothing and food, similarly developers have opinion about different style of naming. Some developers who are coming from embedded or real-time software development might like smaller names then developers of business applications.&lt;br /&gt;
&lt;br /&gt;
==Elements of naming conventions==&lt;br /&gt;
There are number of elements that define the basics of naming conventions. They actually differentiate one naming standard from another one. These elements are influence by the factors we discussed in last section. &lt;br /&gt;
===Length of identifiers===&lt;br /&gt;
This element is part of big debate both in professional and academic circles, what is good, brevity or expressiveness? Some standards recommend fixed size names, some don’t allow abbreviations, some ask to add specific characters to define the type of identifier (like use of I to represent interface classes etc.).&lt;br /&gt;
===Letter case and numerals===&lt;br /&gt;
Some conventions have rules about case of letters according to there types (Like first Uppercase letter for class names and first lowercase letter for method names) and some use no restriction on letters case but add numbers or special characters to identifies the type of identifiers (Like in ruby @ use for public variables etc.)&lt;br /&gt;
===Word boundaries===&lt;br /&gt;
For multiple words most of languages do not allow whitespaces in identifier names. Some recommend using underscore (“_”) character as separator or use of [http://en.wikipedia.org/wiki/CamelCase CamelCase]. CamelCase technique uses uppercase letter to define the word boundaries. For example,&lt;br /&gt;
 EmployeeType&lt;br /&gt;
 &lt;br /&gt;
 addOrder	&lt;br /&gt;
CamelCase works most of time but with acronym it procedures bad names like DaoEmploye.&lt;br /&gt;
&lt;br /&gt;
=General naming conventions=&lt;br /&gt;
There are few naming conventions that are not specific to any language but include the basic principles of program languages. In these conventions naming of identifies not only reflects the domain but also platform specific types too. &lt;br /&gt;
==Hungarian notations==&lt;br /&gt;
This is a well-known naming convention that incorporates purpose or type of identity with its name. Examples,&lt;br /&gt;
&lt;br /&gt;
 IEmployeeType // Interface name&lt;br /&gt;
 &lt;br /&gt;
 btnSubmit // Submit Button &lt;br /&gt;
 &lt;br /&gt;
 arrEmployees // employees array&lt;br /&gt;
 &lt;br /&gt;
 strUsername // user name in string&lt;br /&gt;
&lt;br /&gt;
==Positional notations==&lt;br /&gt;
This convention mostly used in mainframe and COBOL environment where system usually has limitation on numbers of character use for identifier names. A typical scheme is something like, two characters for application name, three characters for module or process name in that application and rest is numbers to make them unique. &lt;br /&gt;
&lt;br /&gt;
 OPCAT001 // OP - Order processing, CAT - Catalog, 001 - first variable&lt;br /&gt;
&lt;br /&gt;
=Language specific naming conventions=&lt;br /&gt;
==Java==&lt;br /&gt;
Sun has a very comprehensive guideline for [http://java.sun.com/docs/codeconv/ Java source coding]. It includes everything from source code organization to naming classes. It is difficult to include everything here. I am going to just specify the naming convention for basic things,&lt;br /&gt;
&lt;br /&gt;
===Packages===&lt;br /&gt;
Prefix of package names is always in all lowercase. It is also recommended to start the package names from top-level domain names i.e., com, edu, org, mil, net. Examples, &lt;br /&gt;
&lt;br /&gt;
 com.sun.lang, edu.ncsu.csc517.pg&lt;br /&gt;
&lt;br /&gt;
===Classes=== &lt;br /&gt;
Class names should be nouns and starting character should be capital. If name requires any division, then use mixed case where every starting character is capital. Examples, &lt;br /&gt;
&lt;br /&gt;
 class Employee&lt;br /&gt;
 &lt;br /&gt;
 class GraduateStudent.&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
&lt;br /&gt;
Names for interfaces should also follow the class name conventions. Examples, &lt;br /&gt;
&lt;br /&gt;
 interface DataAccessObject&lt;br /&gt;
 &lt;br /&gt;
 interface StudyType.&lt;br /&gt;
&lt;br /&gt;
===Method Names===&lt;br /&gt;
Method names should start with some verb and first letter is in lowercase. Examples, &lt;br /&gt;
&lt;br /&gt;
 runApp()&lt;br /&gt;
 &lt;br /&gt;
 addCustomerOrderInformation&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
Variable names also follow method naming rules. Examples, &lt;br /&gt;
&lt;br /&gt;
 studentId&lt;br /&gt;
 &lt;br /&gt;
 employeeName&lt;br /&gt;
&lt;br /&gt;
===Constants=== &lt;br /&gt;
Class constants and ANSI standard constant should be all upper case separated by underscores (“_”). Examples, &lt;br /&gt;
&lt;br /&gt;
 EMPLOYEE_MAX_AGE&lt;br /&gt;
 &lt;br /&gt;
 WINDOW_WIDTH&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
Most of the time, Ruby and Ruby-on-Rails follow the same naming convention like Java. But there are a few differences. One more thing we should be careful about Ruby and Ruby-on-Rails is, since they follow convention over configuration schema, some naming rules are more important for successful execution of application. &lt;br /&gt;
&lt;br /&gt;
=== Local variables===&lt;br /&gt;
All lowercase letters are separated by underscores. Examples: &lt;br /&gt;
&lt;br /&gt;
 employee_age&lt;br /&gt;
&lt;br /&gt;
If it is starts with a capital letter then it is a constant. Example &lt;br /&gt;
&lt;br /&gt;
 Constant=10&lt;br /&gt;
&lt;br /&gt;
===Instance variables===&lt;br /&gt;
Starts with single “at” sign (@) follow by name. It is suggested to have all lowercase for variable name after @ sign. Examples,&lt;br /&gt;
&lt;br /&gt;
 @name&lt;br /&gt;
 &lt;br /&gt;
 @address&lt;br /&gt;
&lt;br /&gt;
===Instance Method===&lt;br /&gt;
Starts with lowercase letter follow by digits, underscores and letters. Examples, &lt;br /&gt;
&lt;br /&gt;
 paint_door&lt;br /&gt;
 &lt;br /&gt;
 manager?.&lt;br /&gt;
&lt;br /&gt;
===Class variables===&lt;br /&gt;
Starts with double “at” signs (@@) and followed by letters, digits, and underscores. Examples,&lt;br /&gt;
&lt;br /&gt;
 @@employee&lt;br /&gt;
&lt;br /&gt;
===Constants=== &lt;br /&gt;
Starts with an upper case letter followed by other characters. Sometimes, developers use all upper case names for constant. Examples,&lt;br /&gt;
&lt;br /&gt;
 PI&lt;br /&gt;
 &lt;br /&gt;
 MAX_AGE.&lt;br /&gt;
&lt;br /&gt;
===Class and Modules===&lt;br /&gt;
Class and module names start with uppercase. Examples, &lt;br /&gt;
&lt;br /&gt;
 Class Employee&lt;br /&gt;
 &lt;br /&gt;
 module DatabaseFunctions.&lt;br /&gt;
&lt;br /&gt;
===Global variables===&lt;br /&gt;
Starts with dollar ($) sign and followed by characters. Examples, &lt;br /&gt;
&lt;br /&gt;
 $company&lt;br /&gt;
&lt;br /&gt;
=Tools=&lt;br /&gt;
&lt;br /&gt;
Developing naming conventions is a smaller job then actually making sure those rules are being followed by the team. Luckily there are few tools available that make this task easier. I have used [http://checkstyle.sourceforge.net CheckStyle] on my job and it worked beautifully. Checkstyle is a fully configurable development tool that makes sure that code is following proper naming conventions. It has integration available with all well known development environments. I have included few links to tutorials using checkstyle in Eclipse and Netbeans in links section.&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
Cost of software development keeps increasing and especially maintenance cost is hurting lot of in-production applications. Major contributor to high cost is associated with difficulty to understand the existing code. A lot of time documentation is not synchronized with code updates. In those cases the importance of code readability increases even more. Having proper naming conventions not only improves the development time but it also reduces the cost of maintenance.&lt;br /&gt;
&lt;br /&gt;
Establishing naming convention is very tricky area. It should not be develop in isolation. Team’s developers’ suggestion should also consider besides looking at industry standards. All successful open source projects start with proper naming conventions. I have included few links, in case someone need some examples.&lt;br /&gt;
&lt;br /&gt;
=Links=&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/CamelCase CamelCase]&lt;br /&gt;
* [http://www.wikihow.com/Improve-the-Readability-of-Your-Software-Code How to Improve the Readability of your software code]&lt;br /&gt;
==Coding conventions for languages==&lt;br /&gt;
*ActionScript(Flex): [http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions Flex SDK coding conventions and best practices]&lt;br /&gt;
*C++: [http://en.wikibooks.org/wiki/C%2B%2B_Programming/Code_Style C++ Programming/Code Style]&lt;br /&gt;
*C++: [http://geosoft.no/development/cppstyle.html GeoSoft's C++ Programming Style Guidelines]&lt;br /&gt;
*C#: [http://www.tiobe.com/standards/gemrcsharpcs.pdf Coding Standard: C# (Philips Medical Systems)]&lt;br /&gt;
*D: [http://www.digitalmars.com/d/1.0/dstyle.html The D Style]&lt;br /&gt;
*Erlang: [http://www.erlang.se/doc/programming_rules.shtml Erlang Programming Rules and Conventions]&lt;br /&gt;
*Java: [http://java.sun.com/docs/codeconv/ Sun official Java coding style]&lt;br /&gt;
*Lisp: [http://mumble.net/~campbell/scheme/style.txt Riastradh's Lisp Style Rules]&lt;br /&gt;
*Mono: [http://www.mono-project.com/Coding_Guidelines Programming style for Mono] &lt;br /&gt;
*Perl: [http://perldoc.perl.org/perlstyle.html Perl Style Guide] &lt;br /&gt;
*PHP::PEAR: [http://pear.php.net/manual/en/standards.php PHP::PEAR Coding Standards]&lt;br /&gt;
*Python: [http://www.python.org/peps/pep-0008.html Style Guide for Python Code]&lt;br /&gt;
*Ruby: [http://itsignals.cascadia.com.au/?p=7 Ruby and Rails Naming Conventions]&lt;br /&gt;
==Coding conventions for projects==&lt;br /&gt;
*[http://httpd.apache.org/dev/styleguide.html Apache Developers' C Language Style Guide] &lt;br /&gt;
*[http://lxr.linux.no/source/Documentation/CodingStyle Linux Kernel Coding Style] &lt;br /&gt;
*[http://www.mozilla.org/hacking/mozilla-style-guide.html Mozilla Coding Style Guide] &lt;br /&gt;
*[ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/share/misc/style The NetBSD source code style guide (formerly known as the BSD Kernel Normal Form)]&lt;br /&gt;
==CheckStyle==&lt;br /&gt;
*[http://checkstyle.sourceforge.net/ CheckStyle project website]&lt;br /&gt;
*[http://blogs.sun.com/geertjan/entry/checkstyle CheckStyle with Netbeans]&lt;br /&gt;
*[http://www.testearly.com/2007/06/06/agile-developers-toolbox-checkstyle-for-eclipse/ CheckStyle with Eclipse]&lt;br /&gt;
*[http://eclipse-cs.sourceforge.net/ Checkstyle plugin for Eclipse]&lt;br /&gt;
*[http://javaboutique.internet.com/reviews/checkstyle/ Good tutorial with some background]&lt;/div&gt;</summary>
		<author><name>Arashid</name></author>
	</entry>
</feed>