Talking about Databases and Objects

Source: Deep Learning on Medium

Talking about Databases and Objects

In the last posts, we have talked about databases, and also we have been working with objects. They both are ways to use the data around the project we are building, combine that data, and produce new information from it. We saw that the main objective of databases is to keep the information safe and be able to return that information every time we need it. We also see how, with objects, we can build the logic of our project. We create classes with attributes and functions, and then we can use them as objects in other places of the application combining different objects of different characteristics.

We have seen these things in previous posts. Inclusive, in the last part of the previous post, we use them (Objects and Databases) together. Both things are used in different moments of our programs. We first build the objects and work with the logic of what the user is using in our program. When the action executed is to save the information gathered, we save it into the database. After that, we retrieve the information again, rebuild the objects, and present them to the user to keeps working in what he is doing.

Taking into account this, we can say that, in a general way, databases are used to save information and objects to build logic. Still, there is one thing, seeing the powerful engine the relational databases have using the SQL language. Why we cannot create the logic with SQL into the database and return the information?? We need objects at all??

Actually, this is a question of taste. We can build our entire system project creating the logic into the database, saving and retrieving information directly. Also, it is also known that the processes that we try to build as logic with our objects are faster if we do them directly in the database. Nevertheless, using objects is the more recommended way, more if you are building a big project with so much info inside. Objects allow us to keep things organized. The languages are more readable if we use objects in our logics. Also, languages have many prebuild functions that help us to build our ideas faster.

Seeing the last post, we can see what is to use the information gathered directly from the database and what is to create objects from the information. We also retrieve data from the database. If you check, you realize that working with the logic inside the database seems faster, smaller, and easier. In real projects, this question is conditioned. First, the language we select is deterministic because languages as CSharp and Java are object-oriented only, so we are restricted from working in that way. Others like Python and PHP give us the chance to choose how we want to do our things, with objects or without objects.

Second the size of the project, in large projects, to maintain a large amount of data without objects is very difficult. Also, it gets complicated to relate those objects together while building our logics.

Third, the amount of attributes in every table is also important. Large tables are difficult to work with. Personally, I prefer to see the size of the project and try to look forward, if I preview the logics are going to be complex, I choose objects.

Conclusion
In here, we talked about Databases and Objects. Most of the time, we use them together to get a project more organized and well structured. You can choose the way you feel right.

Thanks