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