A class e.g School: has member data students and member functions teachers.
The functions teach the students.
Another class e.g Industry: has its own data members and member functions
For the student to work for the industry, there need to be a relation between them.
why not just use a regular member? |
The regular member cannot provide the services need by the industry.
There are several ways of creating this relationship.
a:: composition:: build the industry class to be composed of the School class. So it has regular access to the student data member.
b:: inheritance:: let the industry inherit all the public functions of the school class. So that via the
get member functions of the school, the industry can have access to the students data member.
c::friendship:: In the last 2 approaches, we create the industry to be composed entirley of the School class(case a) or atleast all public functions of School (case b).
This makes the The Industry to access some other parts of School that are not important for them like payment records and other stuff.
For the industry to access solely student data, you would get a friend.