当前位置:网站首页>Member and non member functions

Member and non member functions

2022-04-23 22:05:00 Scarcity risk humility

Member functions : Functions defined in a class ;
Nonmember functions : Functions that are not defined in a class ;
So whether to choose the member function of the class or the non member function of the class ?

Object oriented requires , Put the functions that manipulate the data together with the data . But that doesn't mean choosing member functions . From the perspective of packaging , Of a member function moringAction Encapsulation is lower than non member functions . If something is encapsulated , It is no longer visible . The more things are encapsulated , The less people can see it . So classes that use non member functions , Low encapsulation . And the less people see it , The more flexibility we have to change it , Because our changes only directly affect those who see the changes . therefore , The more things are encapsulated , The greater the ability to change something .

Data within the object under consideration . The less code you can see the data ( Visit it ), More data can be encapsulated , And the more free we are to change the object data . Now if a member function 、 Non member functions can provide the same function , We choose non member functions .

版权声明
本文为[Scarcity risk humility]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232201249834.html