It doesn't work in the real world.
To a degree, yes the real world does work that way, military ships are refitted, altered and reassigned to new roles, until they're useless and played out. Then we sell them to our allies.
The USA could have kept Essex class carriers around ...
Built for WWII, some stayed in service through early 1975 . Just as the USS Enterprise of the Constitution class was refitted as the Enterprise class, the Essex class USS Hancock was refitted as the one of the five ship Hancock class.
... and what the hell, maybe a couple battleships, too.
Might want to sight a different example there too, the battleship Missouri had a life span of nearly 48 years
Surely they were capable of defeating some country, somewhere.
Iraq maybe, during Operation Desert Storm, the battleship Missouri fired 28 cruise missiles into Iraqi targets, plus shore targets with her main guns..
Oh, and the USS Constitution was used on overseas missions 57 years after being launched and is still in active service after 214 years, old girl doesn't get out much anymore.
------
Similarly, the Connies and Enterprises (and other variants?) would have remained in service through certainly the early decades of the 24th century, then transferred/sold into the service of Federation member worlds home-fleets or sold to trusted Federation allies. They would be periodically refitted and upgraded, their 23rd century weapons and sensors removed and superior replacements installed.
By the time of the Dominion War, the space frame of some of the ships would be well over a century old, hardly a front line vessel, but still capable of rear area patrols and offensive missions.