In Chapter 19 of “C Programming: A Modern Approach”, the idea of encapsulation (although ‘meager’ in C programming language) is introduced.
As motivation for implementation of encapsulation, the author alludes to the importance of protecting objects from being accessed by clients. Comments about avoiding the “corruption” of data fields within structures are referenced.
Perhaps because I am still quite a novice in software development in general (I’ve only ever written small programs...with a few .h and .c files), I don’t really understand the necessity of “protecting objects”.
Ultimately, doesn’t the programmer (with explicit code) dictate whether or not an object is directly accessed? It’s not like the compiler will “accidentally” access a structure and modify members, right?
From my understanding, the “corrupting access” would only occur if there was an explicit piece of code that said “access that structure and alter the data”...and presumably the piece of code responsible for initiating that action was user-generated.
Thus, is the only purpose of encapsulation to protect the “purpose of program” from user-errors incurred throughout the actual programming process?
Thanks!