The whole original idea behind the patent system is that you would be granted a time-limited monopoly in exchange for making your idea “patent” (frequently pronounced “pay-tent”, and meaning “obvious”), rather than trying to maintain it as a trade secret (in the formal, legal sense).
You can argue that the monopoly term is too long, or that patents are being granted on things that are already obvious, or that you don’t like the whole idea of it; but the fact is that the monopoly vs. disclosure trade-off, and its public utility, was and is the intention behind the patent system.