WEBVTT

00:00:00.500 --> 00:00:02.570
A neighborhood library lends tools.

00:00:03.470 --> 00:00:07.038
Branch three has four drills, and three are on the shelf.

00:00:07.937 --> 00:00:09.239
Someone borrows one.

00:00:10.137 --> 00:00:12.116
We need a count that is always right.

00:00:13.015 --> 00:00:14.864
We give the shelf to one module.

00:00:15.762 --> 00:00:18.965
Its public functions are how other parts of the app use it.

00:00:19.864 --> 00:00:21.817
Its private memory holds the count.

00:00:22.715 --> 00:00:24.629
The module's code connects the two.

00:00:25.528 --> 00:00:27.806
In the project, a module is a folder.

00:00:28.705 --> 00:00:31.283
The functions and the code are in mod dot r s.

00:00:32.181 --> 00:00:35.215
Everything the module saves is declared in its memory folder,

00:00:35.450 --> 00:00:36.973
in a numbered version file.

00:00:37.871 --> 00:00:39.356
This one is version one.

00:00:41.467 --> 00:00:43.550
The call arrives at a public function.

00:00:44.450 --> 00:00:47.979
The module's code checks the shelf, then uses its key to open

00:00:47.992 --> 00:00:49.294
its own memory and write.

00:00:50.193 --> 00:00:51.417
Three becomes two.

00:00:52.315 --> 00:00:54.958
Now some other code tries to set the count directly.

00:00:55.857 --> 00:00:56.651
It cannot.

00:00:57.549 --> 00:01:00.700
Outside the module, this memory is a sealed handle.

00:01:01.599 --> 00:01:04.229
Other code can hold the handle and pass it along.

00:01:05.127 --> 00:01:07.510
Only the module's own code holds the key.

00:01:08.409 --> 00:01:11.456
So when the count is wrong, there is one place to look.

00:01:12.354 --> 00:01:15.739
The seal is a rule the compiler enforces between modules.

00:01:16.638 --> 00:01:18.591
It keeps the app's own code honest.

00:01:19.489 --> 00:01:22.588
The rules inside the module are still ours to get right.

00:01:24.733 --> 00:01:26.230
Someone asks for the ladder.

00:01:27.130 --> 00:01:28.875
There is one, and it is out.

00:01:29.774 --> 00:01:32.000
The module checks, and answers no.

00:01:32.899 --> 00:01:34.526
Nothing in memory moved.

00:01:35.425 --> 00:01:38.914
This order is a design rule, and you should ask for it by name.

00:01:39.813 --> 00:01:42.365
Decide every refusal before the first write.

00:01:43.263 --> 00:01:46.531
If code writes and then returns an error, the write stays.

