Do you think that friend functions violate encapsulation-01154
This subjective question is related to the book/course vu eco403 Macroeconomics. It can also be found in vu eco403 Mid Term Solved Past Paper No. 1.
Question 1: Do you think that friend functions violate encapsulation. Justify your answer.
Answer:
The friend functions of a class have access to the private data members of class. Despite being a good thing, there is possibility of vulnerability. We are opening our thoughts, inside view for somebody else. Without having 100% trust, it will be risky to make our thoughts and feelings public. We want that our private data is accessible to someone outside, not public for everybody. Otherwise, the data encapsulation and data-hiding concept will be violated. We keep the data members private and declare some specific functions that are not member of the class but friend of the class. As friends, they have access to the inside data structure of the class despite not being members.