We consider the quantum dynamics of a free nonrelativistic particle moving in a cavity and we analyze the effect of a rapid switching between two different boundary conditions. We show that this procedure induces, in the limit of infinitely frequent switchings, a new effective dynamics in the cavity related to a novel boundary condition. We obtain a dynamical composition law for boundary conditions which gives the emerging boundary condition in terms of the two initial ones.