Encapsulation does not mean that there should not be access to members. This means that you should allow access only to those members that should be used, mainly restricted access, and not access.
By making something publicly available, you allow access by making it private, and you are not.
In this article, we will look at more detailed information about various access modifiers:
http://www.csharp-station.com/Tutorials/lesson19.aspx
In this article, they give a good example:
using System; class BankAccountProtected { public void CloseAccount() { ApplyPenalties(); CalculateFinalInterest(); DeleteAccountFromDB(); } protected virtual void ApplyPenalties() {
When a programmer wants to close an account, they donโt need to worry about the various steps that go into this:
- ApplyPenalties
- CalculateFinalInterest
- DeleteAccountFromDB
They should simply say that they want it to close and that all necessary steps will be taken. This is why CloseAccount is publicly available and others are not.
source share