I was going to start by stating the difference is “a” is unspecific, “the” implies the subject is already known.
However as I thought more about it I realized it gets a little more complicated. I’m not academically studied in English, though I am a native speaker.
For example if you say, “Our town has a castle” - that’s a specific castle but you wouldn’t say “our town has the castle.”
Why? It has to do with what the listener knows. “Definite” means the subject is known to the listener. If I’m introducing a castle into the conversation that you don’t know, I’m talking about _a_ castle. Now that it’s introduced, I can tell you about _the_ castle.
It's because the town has one out of the set of all castles.
You can also say "Our town has the castle", which... now there it gets weird. I think it means it doesn't have much, but it has that. Well I guess it's specific in that it is one of the few (specific) things it has going for it.
"Our town has the castle" would mean that of (all the gin joints in) all the towns in all the world, only yours has a castle. Also not academically qualified, also a native speaker.
If there was only one castle then you would save the. For example our town has “the giant duck” (fictional fibreglass statue)
"Our town has the castle". Is reasonable for meaning that it has the best/oldest/most historical/largest one. Or in general that the specific castle that has something which separates it from the rest.