The 2 decades thing does make sense. Its not 2 decades for "the next class" its 2 decades for the next heavy exploration cruiser. So think of, Excelsior class, Ambassador class. those probably had the same length of design time, incorporating new technology, probably the first vessel in a new generation of vessels that incorporate new technology from the ground up instead of tacked on.
Designed for a 50 year life, but some ships last longer or shorter, as the saying goes ,its not the years, its the mileage, so by 2401, there are probably still Galaxy class ships out there doing there job, with some having been destroyed, decommissioned, but a number being refitted and still serving after 40 years. There not the bell of the ball anymore, probably still seen as "luxury" for its size.
Then some ships may leave "Starfleet" and be given to member planets for there own fleets or defense, exploration etc. Species X may join starfleet and have similar goals, but some goals on defense or exploration may not be a priority for starfleet, so they use there own ships, or ships donated to do there own thing. and if a war or other thing happens, they can be recalled.
That was kinda my head cannon on DS9 on why they had so many excelsiors and mirandas, there all member fleet ships being recalled for war use.
Looking at a "refit" there are many kinds of refits, Carriers do a "refit" after every deployment, fixing broken things, installing new tech etc. that takes like 6 months. then there's the bigger "refits" refueling the nuclear engine, or installing a new island like the Enterprise.
So for Starfleet ships, they may have a 5 year "refit" that they bring them in, do depot level maintenance, replace some stuff, but generally a refresh and check, maybe take a couple weeks, maybe a month.
Then there's the 10 year "moderate" refit, new systems integration, any big things, couple months,maybe 6.
Then theres a 20 year "Major" refit, change out warp coils, stem to stern inspection and redo, that takes like a year.
Very rarely its a "keel up" refit like the TOS Enterprise.
Ships can last for quite a while with some upkeep.