extract duplicated code to abstract parent class AbstractComponent<T>
write Query<T> component. untested
make entityManager a private filed in root class