Refit/building to a different class is only possible if the cost to refit to the different class from the class the shipyard is tooled for, is 20% or less than the build cost of the class the shipyard is tooled for.
Assuming there is no change in tonnage, the refit cost is 125% of the cost of all components that have to be added compared to the old class. There is no credit for components that need to be removed.