Answer to Question #163346 in C++ for Julia

Question #163346

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++ developeranalyze 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.


1
Expert's answer
2021-02-12T12:05:05-0500

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.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment