Japanese castles can be divided into 3 categories, plains castle, mountain castle and hill castle.
Definition of plains castle is that the castle is located in flat and urban areas. This type includes Matsumoto castle, Nagoya castle and Nijo castle. On the other hand, mountain castle stands on the mountain located at the isolated area. This type includes Takeda castle and Bitchu-Matsuyama castle and this type of castle is usually built as a fortress. The last hill castle is the one you see a lot in Germany, the castle is located on a urban area but on top of the hill. This type includes Osaka castle, Himeji castle. Kumamoto castle and Matsuyama castle.
Foundation of the mountain castle was mostly depended on the nature but plains castle and hill castle had to create defense systems to protect the castles. These defense systems were walls and moats.
Especially the moat was quite important for the defense. Osaka castle, which experienced two great battles during feudal period had two moats; Inner and outer moats. When ruler of the castle, Hideyori Toyotomi lost the first battle against Ieyasu Tokugawa in the winter of 1614, he had to plug up the outer moat due to the condition of the ceasefire. Then, this made easier for Ieyasu to win the second battle in summer 1615. The castle burnt down after the defeat of the battle and Ieyasu forced Hideyori to commit suicide - HARAKIRI.