I've always thought Starfleet ships were somewhat modular. Swap out the sensor suite / warp core / deflector, plug in the new type and off you go. Thus really old space frames like The Excelsior remain viable and in service into the TNG era.
Add to this, every light year explored brings a huge volume of space into play - more and more ships are required all the time. Older models are perfect for run of the mill operations, freeing state of the art ships up for front line exploration.