Why in the past were European ships built with high wooden "castles" fore and aft?

to have better view
2374
to manage the deck more easily
1726
to improve ship defense
8780
to improve ship stability
5229
These were built to better resist boarding, commonly used in the naval warfare (especially by pirates). Boarders needed to attack these castles with great difficulty, while archers or harquebusiers could sweep the enemy decks.
correct this question
globalquiz.org
reach: rather globalhistorymilitarynaval warfarenavysea battlesshipstechnology