Understanding Encapsulation


A basic principle of object-oriented design is encapsulation, which means that a class hides the internals while providing a robust and flexible public API (meaning properties and methods) by which it can interact. The benefit of good encapsulation is flexibility and scalability. When one class can peer into and interface directly with the code of a different class, it makes for very rigid designs. If any part of a class's internal code changes, it could potentially break the entire application in such a scenario. However, when all classes interface only by way of a public API, as long as the public API remains the same, the internal code of the classes can change without necessarily breaking anything. That means greater flexibility.

Although the basic principles of good encapsulation are fairly obvious and even intuitive, there are some common errors that programmers make with regard to encapsulation. Those common errors generally involve absolute references within the class such as _root or _global. Although there are exceptions, it is very unlikely that _root or _global should appear within a class.




Macromedia Flash 8 ActionScript Training from the Source
Macromedia Flash 8 ActionScript: Training from the Source
ISBN: 0321336194
EAN: 2147483647
Year: 2007
Pages: 221

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net