Thus, the older a galaxy, the more rich its gas is in heavy elements, a process called chemical evolution. The two most distinct galaxy types are ellipticals and spirals . Ellipticals have no ongoing star formation today, spirals have alot. The answer is how rapid their initial star formation was when they formed. If star formation is rapid and all the gas is used up in an initial burst, the galaxy forms as a smooth round shape, an elliptical.
Gas falling into a spiral disk is slowed by collisions and star formation continues till today.
The spiral arms and patterns are due to ongoing star formation, whereas ellipticals used all their gas supplies in an initial burst 14 billion years ago and now have no ongoing star formation. Galaxies orbit each on in clusters. Those orbits can sometimes cause two galaxies to pass quite close to each other to produce interesting results. Solid objects, like planets, can pass near each other with no visible effects. However, galaxies are not solid, and can undergo inelastic collisions, which means some of the energy of the collision is transfered internally to the stars and gas in each galaxy.