Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save PEMapModder/8afa8492f2dd5e34af2f to your computer and use it in GitHub Desktop.

Select an option

Save PEMapModder/8afa8492f2dd5e34af2f to your computer and use it in GitHub Desktop.

Source: http://www.cprogramming.com/tutorial/lesson12.html

Let's look at these different access restrictions for a moment. Why would you want to declare something private instead of public? The idea is that some parts of the class are intended to be internal to the class--only for the purpose of implementing features. On the other hand, some parts of the class are supposed to be available to anyone using the class--these are the public class functions. Think of a class as though it were an appliance like a microwave: the public parts of the class correspond to the parts of the microwave that you can use on an everyday basis--the keypad, the start button, and so forth. On the other hand, some parts of the microwave are not easily accessible, but they are no less important--it would be hard to get at the microwave generator. These would correspond to the protected or private parts of the class--the things that are necessary for the class to function, but that nobody who uses the class should need to know about. The great thing about this separation is that it makes the class easier to use (who would want to use a microwave where you had to know exactly how it works in order to use it?) The key idea is to separate the interface you use from the way the interface is supported and implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment