The concept of DOF (depth-of-field) is to use information about Z values and use it to blur objects.
The more out of depth they are, the more they are blurred.
This is a simple example :
I used a cube. Then I multiplied by the modifier array.
It can use other objects. I selected the Node Editor.
I enabled the Composite Node, see image below:
Add and these converter-> Color Ramp.
Then add the Add – Filter – Blur and Add-> Vector-> Map Value.
Then connect them this way.
I marked with red areas to be modified with numbers from 1 to 3.
Change the numbers 1 and 2 so you get a result of the final image (see 3).
As you can see Color Ramp is directly linked with the Composite.
Do it again, but like the picture below:
The result will be: