Let us consider the Lewis Structure for the Water molecule. Lets define Lewis structure first – “Lewis Structures are visual representations of the bonds between atoms and illustrate the lone pairs of electrons in molecules“.
Oxygen has 6 valence electrons and Hydrogen has 1; altogether water molecule has 8 valence electrons. If we pay attention and analyze individual atom, we see every atom has fulfilled it octet – Hydrogen has 2 electrons and Oxygen has 8 electrons(counting 2 it got from 2 Hydrogen atoms).
In chemistry, a valence electron is an electron that is associated with an atom, and that can participate in the formation of a chemical bond; in a single covalent bond, both atoms in the bond contribute one valence electron in order to form a shared pair.
valence electrons as
public methods and non-valence electrons as
private/protected methods. OOP suggests to keep
data at the core so that it is always private. So, consider private data as nucleus of the atom.
When two unstable atoms bond with each other to form a rather stable structure sharing their valence electrons, then yields more usable stable chemical structure. Now lets make analogy:
- bonding –> message passing
- unstable atoms –> Individual software components (say classes) that need to cope with other entities to form a usable software.
- valence electrons –> Public methods (public API) that take part in assembly
- lone pair of electrons –> Public methods that might not be used in that software at all.
- core electrons –> Private methods that do not take part in
- Atom nucleus –> Private data of object; never shared directly with other
- Yielded usable stable chemical structure –> A releasable software component
Atomic analogy of OOP
In my opinion, all of them have different purposes to fulfill. I have tried to list them below. If you want to understand the concept of OOP then first go through this post “Atomic Analogy of OOP Concept“.
- Primarily, it is to converge / decrease the dependencies of outer world to these data/method. It makes sure that the developers are not going to use these data/methods and are safe to be modified if deemed.
- So, it makes sure that its fine to make some tweak in this portion of code. It confirms that its safe and its not gonna trouble the library users.
- Also, since outer world has no direct connect strings whatsoever, therefore, I can freely change the behavior and be confident that only the same class is gonna be affected.
- I might(not) have test coverage for this.