Merits and Demerits of Friend Functions – Object Oriented Programming (OOP)

Download our Android App from Google Play Store and start reading Reference Notes Offline.

merits and demerits of friend functionsMerits and Demerits of Friend Functions
Object Oriented Programming (OOP)
Third Semester | Second year
BSc.CSIT | Tribhuvan University (TU)

Merits and demerits of Friend Function
Friend functions is a special function in object oriented programming, which is used to get access the private members of a class from outside the class. It also can take objects of two classes as arguments and operate on their private members and hence can bridge two classes. Based on its work it has some merits and demerits which are explained below;

Merits of friend function

  • Friend function act as bridge between two classes by operating on their private datas.
  • Must have access to source code for the class to make a function into friend.
  • Able to access members without need of inheriting the class.
  • Allows a more abvious syntax for calling a function rather than member function.
    For example num.square(); is less obvious than square(num);
  • Can be declared either in the public or the private part of a class.
  • Can be used to increase versatility of overloaded operator.

Demerits of friend function

  • Friend function have access to private members of a class from outside the class which violates the law of data hiding.
  • Breach of data integrity
  • Conceptually messy
  • Lead to spaghetti-code situation if numerous friends muddy the boundary between classes.
  • Maximum size of memory will be occupied by objects according to size of friend members.
  • Cannot do any run time polymorphism in its members

Posted By : Digvijay | Comment RSS | Category : Third Semester
Tag : ,

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Wordpress DMCA
Community | Toolbar | Android App | Founder/Developer : Hari Prasad Chaudhary | CSIT Portal Manager : Digvijay Chaudhary