-
Book Overview & Buying
-
Table Of Contents
Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]
By :
Encapsulation is a valuable OOP feature that C++ offers through the proper usage of classes and access regions. Encapsulation offers uniformity in the manner in which data and behaviors are manipulated. In general, it is unwise to forfeit the encapsulated protection that a class offers.
There are, however, selected programming situations in which breaking encapsulation slightly is considered more acceptable than the alternative of providing an overly public interface to a class. That is, when a class needs to provide methods for two classes to cooperate, yet, in general, those methods are inappropriate to be publicly accessible.
Let’s consider a scenario that may lead us to consider slightly forfeiting (that is, breaking) the sacred OOP concept of encapsulation: