Educational outcomes
Student:
- explains how to implement different concepts of objectivity in relational model using natural language (understanding);
- identifies and corrects errors in the source code, which is an implementation of the above structure;
- lists constructs implemented in the source code (understanding);
- implements the above structures using the selected programming language (application);
- indicates functional differences between two selected programs based on code snippets source (analysis);
- creates a program that implements specific business requirements using the constructs learned from the lectures (synthesis);
Justification
Modern programming languages are mostly based on the object paradigm. Therefore, its practical understanding is a necessary basis for working in this profession. Moreover, programmers often make systems based on analytical materials. And these largely use object-oriented graphical notations (such as UML). During this and the next lessons, you will deepen your theoretical bond, but first of all you will learn how to implement different concepts from object-orientness. This will allow you to design and implement modern business applications.
Popularity of the relational model
Let's start with the fact that practically every designer or programmer who creates a little bigger system uses a database. And nowadays the term "database" still means "relational database". From the point of view of the designer or a programmer, the reasons for this are not very important. The most important thing is to be able to deal with this situation. What is the problem with the relational model? We must combine two, or rather three, worlds: object-oriented used in analysis, object-oriented used in programming languages (smaller) with the relational world used in the data warehouse. In other words: by analogy with the transition from a rich object model (analysis) to a poorer object model (Java, C#, C++), we need to provide object-oriented mapping to relational one and vice versa.
Assumptions of a relational model
The exact description of the relational model is beyond the scope of the MAS lecture, but we will briefly recall the basic concepts:
- The equivalent of classes are tables.
- Each table can have any number of columns storing attribute values. Each such column is of a certain type, eg number, text, binary value. There are actually more types, but we will not take care of them.
- Table rows (called tuples or records) describe instances - they are equivalent to objects.
- The order in which the records appear in the table is not business-relevant.
- Each table can have a primary key and foreign keys.
- The primary key is used to uniquely identify a particular record, and is essential for connecting tables (the equivalent of an association).
- Foreign key identifies the associated tuple, usually from another table, such as Person and Company tables. One of the people has a primary key value, such as 12.3K. In the Company table, there is a column containing the foreign key relating to the person and telling us that the person with the key value of their primary key (12.3K) owns the company.
- Some columns in tables may have a special NULL value. This means that there is no value, eg no maiden name.
- Multi-to-many relationships must be modeled using intermediate tables.
As you can see, the above model is very simple and devoid of most constructions known from object-orientness. I think we will agree that using it means working at a lower abstraction level, more technical than the object model.
In our considerations regarding the relational model and its relationships with the object model, we take into account its classical assumptions. We do not use specific solutions found in some database management systems.
Databases, as a layer of persistency
Let us consider for a moment what are the main reasons for using databases. It seems that one of the most important is the query language. It enables very easy data processing, saving you a lot of work.
Another important argument is obviously performance. Over the years, database management systems have been equipped with a variety of mechanisms (including indexes) that dramatically accelerate the performance of any operation. In many systems, it is true that modern computers are so fast that in many cases they would have managed without a dedicated BD, using only the built-in mechanisms of the development platform.
Indexes in databases speed up access to data. Unfortunately, this is at the expense of more memory consumption (these are some additional data structures that the system needs to store somewhere). Some operations (such as insertion or updates) are also slower (because the system needs to take care of the data and the index for them).
The explosion of popularity of web-based applications has also serious impact on the databases. In such cases, some data persistence mechanism is needed, and BD is usually the most obvious choice.
Other reasons are related to security. Thanks to the built-in mechanisms, we have the ability to control access for different users.
And of course the ability to store a lot of information, but as we have said sometimes it is abused.
We have exchanged so many advantages of relational databases, but do they have any disadvantages? Perhaps the most important is the relational model itself...
Impedance mismatch
The consequence of using relational databases from object-oriented programming languages is a phenomenon known as impedance mismatch. It is due to the need to match "two different worlds": relational and object-oriented.

In the next sections we will discuss various ways of mapping (translating) object constructs from programming language to relational data model. In the remainder of this tutorial we will also describe the tools that we can use to facilitate these operations: Object-Relational Mappers (ORMs).
Class mapping
Mapping classes into tables is relatively straightforward, but you need to be aware of some restrictions. In general, we can say that classes are replaced by tables. Each attribute is stored in a separate column. Its type is similar to the attribute type in the object model. This rule only applies to simple types. In other cases we have to apply dedicated solutions - see the next lesson.
Keys
As mentioned earlier, in the relational model we need keys to identify tuples. Therefore, for each table we add a special attribute - the key uniquely identifying our "object".
There are two approaches to these keys. Some programmers claim that to reduce the size of the data model, we should use business attributes. If we do not have a unique attribute, we should use their combination (the key may consist of several columns).
Another solution is to add a dedicated, non-business-related column. For performance reasons, it is best to have a number (of a sufficiently large type). Moreover, consistently using some convention (eg IDNameTable we will always know what our key is - and this is of course important when writing queries.
This second approach seems to be better: it provides better performance and makes it easier to memorize model details.
What is the reason for the popularity of relational databases? There are many factors and you could write about this quite extensive paper, but let's briefly list the most important ones: