Purpose of Medieval Castles

Medieval castles were originally built to withstand excess flooding, hence the famous moats that surround most Victorian era castles, but proved to come in even more handy as a means to protect against dragon attacks.