This **paradigm** we are following is based on defining the data (variables) on one hand, and creating **separated functions** for working with that data. When calling the function you should pass the data as **parameters**. Data and function are **separated**
Imagine that now we define a new sequence, but we make a mistake:
Imagine now that we define a new sequence, but we make a mistake:
```python3
from Seq0 import *
# -- This sequence is invalid, as it as characteres
* How could you solve that problem? How could you guarantee that the sequence introduced is valid?
* How could you solve that problem? How could we guarantee that the introduced sequence is valid?
One solution is adding a **new function** for checking that a given sequence is ok. Something like this:
...
...
@@ -119,19 +119,19 @@ seq_check(seq1)
...
```
It is ok, but what happens if there are programmers that do not call this function for checking? It is **NOT possible** for you to **assure** that it is going to work in all the cases. It depends on the people using it. Some may call the seq_check() function, but other do not.
This solution is ok, but what if there are programmers that do not call this function for checking? It is **NOT possible** for you to **assure** that it is going to work in all cases. It depends on the people making use of it. Some may call the seq_check() function, but it is not guaranteed
Is it possible to have a **better model** for organizing the data and the functions?
But is it possible to have a **better model** for organizing both the data and the functions?
## Modelling the sequences with object oriented programming
Yes! There are better models. One is the **Object Oriented Programming**
Yes! There are better models. One is **Object Oriented Programming**
In this model, the **data** and the **functions** are grouped together into what is called and **object**. They are no longer separated. You work with **objects.** Every object has a **well defined actions** that you can **perform** on then. These actions are called **methods**
In this model, the **data** and the **functions** are grouped together into the so called **object**. They are no longer separated. You work with **objects.** Every object has **well defined actions** that it may perform. These actions are called **methods**
In order to learn about this new paradigm, let's model the DNA sequences with it
We will think about the **sequences** as **objects**. This objects can have some **properties**, like their name, the chromosome to which they belog or any other information. We also refer to this properties as the object **attributes**
We will think about the **sequences** as **objects**. These objects can have some **properties**, like their name, the chromosome to which they belong or any other information. We also refer to this properties as the object **attributes**
These object also have some **methods**: different actions that can be performed on them, such as calculating their length, the number of a certain bases, their complement, and so on
...
...
@@ -139,7 +139,7 @@ We will learn this model by defining **sequence objects** from **scratch**
### Classes
A [class](https://en.wikipedia.org/wiki/Class_(computer_programming)) is the **template** we use for **creating objects**. Inside the class we define all the **methods**of the objects of that class, and we program their **behaviour**. Let's create a minimum class for working with sequences. We start by defining an **empty class**:
A [class](https://en.wikipedia.org/wiki/Class_(computer_programming)) is the **template** we use for **creating objects** (an object is going to be an instance of that class). Within the class we define and implement all the **methods**that the objects of that class will have. Let's create a very simple class for working with sequences. We start by defining an **empty class**: