What is Encapsulation?

ENCAPSULATION is the grouping of data items and functions into a type. By this we mean, if you have operations you want to perform on a student, you would sum them up, both the properties of the student and the operations you want to perform on them and encapsulate them into a class.

So we would have the class student that can contain properties like

i. Name
ii. Age etc.

And also operations like

i. AssignStudentID
ii. ChangeDepartment etc.

This would make it more organized and resuable.

That's the advantage of encapsulation.

0 comments: