where $X$ is a metric measure space and $J$ is a suitable shape functional. We adapt the notions of $\gamma$-convergence and weak $\gamma$-convergence to this new general abstract setting to prove the existence of an optimal domain. Several examples are pointed out and discussed.