Object oriented programming has 3 main design principles as follows
– offers to derive a new class from an existing one and acquire all the feature of the existing class. The new class which get the feature from the existing class is called the derived class and other class is called the base class.
-this allows the user to hide the information for outside world and doesn’t allow the other user to change or modify the internal values of class.
For example :
if you’re building a banking application that handles details of customer accounts , you might have a Account object with a property called totatBalance and methods called makeDeposit and makeWithdrawal.
The totalBlance property should be read-only. The only way to affect the balance is to make a withdrawal or a deposit.
If the totalbalance property is implement as a public member variable, you can write code that would increase the value of that variable without having to actually make a deposit. Obviously, this would be bad for the bank.
Instead, you implement this property as a private member variable and provide a public method called getTotalBalance,
which return the value of that private member variable. With the variable storing the value of the account balance made made private, it can’t be manipulated directly. Because the only public methods that affect the account balance are makeWithdrawal and makeDeposit , a user has to acually make a deposit if he/she wants to increase the value of this account.
Encapsulation of interanl data and method implementations allow an object-oriented software system to protect and control access to data and to hide the details of implementation, giving you flexible, stable appliaction.
– one term in many forms
I will write this topic as soon as possible.