A fence is used for trapping mobs such as a cow so you can harvest from them or keep them as a pet. To prevent them from de-spawning you must name them using a name tag. They can also be used as a decoration.
-note- the reason why my chickens are in cobble stone and not a fence is for easy access to their eggs. Just jump and you will be able to grab them. File:Mineblocks.png