Immune systems learn. Like human beings, immune systems have critical periods where they are particularly sensitive to learning. If they are not exposed to the typical environmental pathogens at these critical periods the immune system may not respond properly.
Asthma is less prominent among farm children because they are exposed to native pathogens during this critical period. Children brought up without exposure to these things can develop an overreaction. In addition to this supercharged learning capacity that lasts a short time, the immune system also has a less powerful, ongoing learning capacity to combat novel pathogens. This learning process involves what are called B Cells. These are a type of blood cell, part of the immune system, and secrete antibodies in response to perceived pathogens. These antibodies are in effect tattletales. They mark the invader as an enemy so that T-cells (Another type of immune cell) can deal with them. Thanks to way b cells can learn and remember, our body then gets a head start fighting repeat offender pathogens. This memory process is what makes vaccinations work.
This article in this link explains how “naive” immune cells transition into memory cells. Click Here