Senerio:
ATM (Automated Teller Machine) machines are electronic outlets that allow customers to do their basic transactions without interaction of bank’s representative. While programming this ATM in C++, We have created a class named CUSTOMER which stores customer data (i.e. name, NIC, age, address, account balance and transaction history etc.). There is a friend function that wants to access some private information of the class.
Question:
Being a C++ developer, analyze the whole scenario, what do you think, does a friend function contradict the rules of Encapsulation?
Give your opinion in yes or no with strong reasons.
I believe that in this case there is a violation of encapsulation. Because these will be private data classes that can be accessed only through the class interface. The friendly function will have full access to all the fields of the class and cannot be hidden in any way. Since this example uses private user data, it should only be accessed through the class interface.
Comments
Leave a comment