Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Layer Best Practices

I am in the middle of a "discussion" with a colleague about the best way to implement the data layer in a new application.

One viewpoint is that the data layer should be aware of business objects (our own classes that represent an entity), and be able to work with that object natively.

The opposing viewpoint is that the data layer should be object-agnostic, and purely handle simple data types (strings, bools, dates, etc.)

I can see that both approaches may be valid, but my own viewpoint is that I prefer the former. That way, if the data storage medium changes, the business layer doesn't (necessarily) have to change to accommodate the new data layer. It would therefore be a trivial thing to change from a SQL data store to a serialized xml filesystem store.

My colleague's point of view is that the data layer shouldn't have to know about object definitions, and that as long as the data is passed about appropriately, that is enough.

Now, I know that this is one of those questions that has the potential to start a religious war, but I'd appreciate any feedback from the community on how you approach such things.

TIA

like image 460
ZombieSheep Avatar asked Aug 14 '08 10:08

ZombieSheep


People also ask

What should data layer contain?

A data layer object is made up of a list of key/value pairs. A key is a category of things – a book's category, title, or author. Each key could have different values. A book's title key could have a value of 'Ulysses', 'War and Peace', 'A Brief History of Time', etc.

What are the advantages of data layering?

The division of network protocols and services into layers not only helps simplify networking protocols by breaking them into smaller, more manageable units, but also offers greater flexibility. By dividing protocols into layers, protocols can be designed for interoperability.

What is data layer with example?

A data layer is an object that contains all the information you want to pass from your website to a tag manager (for example, Google Tag Manager). The data layer is simply a JavaScript array that is used to store information and send this data to the tag manager.

What is meant by data layering?

A Data Layer is a virtual layer between your website (code and server) and your tag management solution (such as Google Tag Manager), where you can store, process and pass data. Technically speaking it is a JavaScript object, which in some cases will also be referred to as a Universal Data Object (UDO).


1 Answers

It really depends on your view of the world - I used to be in the uncoupled camp. The DAL was only there to supply data to the BAL - end of story.

With emerging technologies such as Linq to SQL and Entity Framework becoming a bit more popular, then the line between DAL and BAL have been blurred a bit. In L2S especially your DAL is quite tightly coupled to the Business objects as the object model has a 1-1 mapping to your database field.

Like anything in software development there is no right or wrong answer. You need to understand your requirements and future requirments and work from there. I would no more use a Ferrari on the Dakhar rally as I would a Range Rover on a track day.

like image 98
JamesSugrue Avatar answered Oct 11 '22 04:10

JamesSugrue