fbpx

Implementing ORM

Implementing ORM

In my previous article, I talked about writing a Database Abstraction Layer. This time I take a look at implementing ORM and how it speeds up the development cycle.

What is ORM?

ORM stands for Object-Relational Mapping and it describes a method of interacting with a database using an object oriented model. Unlike the Database Abstraction Layer (DbAL) I talked about before, ORM maps an object to each entity and entity set within a database. In short a DbAL is both database language and database structure agnostic, while an ORM knows about the structure of a database. An ORM entity object will expose properties that relate to that entity’s attributes, and an ORM entity set object with expose methods that performs queries to return filtered result sets.

Implementing ORM in Practice

There are several ways to implement ORM:-

In my article about DbAL, for the project I talked about, I wrote my own objects. My entity objects were very much value added. Many of the objects provided the methods needed to handle business logic that related directly to them. It made a lot of sense using this methodology in this instance. For performance, I needed to reduce the number of calls between objects. I didn’t want to insert my business logic into my GUI Layer but the GUI Layer needed to talk directly to the ORM objects.

In a more recent web application project, I used Doctrine’s ORM implementation. Using Doctrine meant I didn’t need to hand code each ORM object, but instead the tools I used to create my entities also created my ORM objects. In this case my business logic was kept separate from the ORM objects, allowing me to rapidly create a REST API.

Rapid Development

By implementing ORM in my projects, I was able to rapidly create new sections within the applications I was writing. Retrieving a list of records became standardised, how I interacted with those records also became standardised. This allowed for the rapid development of new areas of the software, I could create a standard interface and connect it to whichever ORM object I want to display. Once my GUI Layer was completed, I could almost forget about it and concentrate on the business logic and structure of the underlying data.

SAMWare UK creates bespoke solutions and websites. Contact us to arrange a chat to discuss your needs and for a free no obligation quote.

Leave a Reply

Your email address will not be published. Required fields are marked *