Ensure to follow the recipe, use the right sized baking dish and avoid overbaking the cake. Adding too much flour or too little oil/sugar can cause for a cake to become dry very quickly. Another important fact to consider is the color of the baking dish. A dark colored pan will absorb the heat more quickly which means your cake will bake faster and there is a higher chance for the cake to dry out.