There are several ways that you can contain your pet and keep them on your property, in your yard, or segregated to a certain part of your yard. There is no one perfect method as they all have some downside or limitation. The key is to understand what you're looking for and find the product that best meets your needs and offers the least number of weaknesses.
The first is probably the most obvious. That would be good old fashioned fencing. Whether it's wood, wire, or plastic, it all accomplishes the same thing, that being keeping your pet in your yard and out of reach of strangers. This is certainly the best option for aggressive dogs. And, as a side note, if you're thinking that this best describes your dog, you better get some help with training before your pet hurts someone. An aggressive pet is a poorly trained pet, and it's a danger to everyone around it.
The downside to hard fences, of course, is the fact they limit your movement as well, can be an eyesore, and can always be dug under with enough time and determination. They're certainly the most costly of all the options, and they're not portable.
The next option is invisible, or electric dog fences. These are generally the kind where you bury a wire around the perimeter that you would like to contain your pet in, hook the wire up to a signal generator, and put a collar on your dog. This collar gives them a shock when they get too close to the buried wire, and the strength of the shock can be varied depending on how "stubborn" your dog is.
These containment systems are somewhat problematic to install, and also prone to wire breakage depending on what you use your yard for. If you desire, you can install them by laying the wire over the turf and letting the grass grow up over it, and this is easier but more prone to breaks and snags. I will say that after a full season you won't be able to find the wire anymore, but it is still quite close to the surface and can be snagged.
Depending on options, they're quite a bit cheaper than hard fences, and when you move you can always take the expensive collars and transmitters with you, leaving the wire buried for the next occupants. The wire can be had for quite cheap, and is a small fraction of the total system cost.