Showing posts with label encapsulation. Show all posts
Showing posts with label encapsulation. Show all posts

Saturday, January 15, 2011

Encapsulation

Encapsulation
The concept of sealing data and methods into an object is known as encapsulation. Its ability is to hide information and internal implementation from the users. Information hiding doesn’t mean to hide information but it means that it gives limited access to user. Access modifiers provides accessibility level for user.



Examples
If you want to meet the president of your country you can’t go directly to meet president. Guard or Security of president will check you and if you have appointment or you have access then you can go to meet him. That’s what encapsulation does. Its guard your data not hides it.  

Take an example of car. All of us drive car when we sit in car and insert key in it and turn it to start the car , the car get started but we don’t know how its starts. We don’t know the internal working of the car. The internal implementation is hidden from the user.


A tracker in a car that helps us trace our car when someone steals our car, so we just let the tracking service provider company know that my car has been stolen I know they can trace it but keep it hidden how are they going to trace it 

Public Access Modifier


We can only access Name because it is public.

Private Access Modifier
To access private variable we have to make property for that variable which will guard the variable and we can access private variable via that property.

Now we can access EngineNo variable via EngineNo1 property.





Protected Access Modifier
Protected variables can be access by inherited class. Let make another class which will inherit clsCar.




Saturday, January 8, 2011

Object Oriented Programming (OOP)

Object Oriented Programming (OOP) 
Object oriented programming (OOP) deals with thing called 'objects'. Objects are just extremely functional ways of organizing information. Object in an OOP language are combinations of code and data that are treated as single unit.

Understanding Whole Mechanism of OOP
To see object oriented working in action, consider your everyday life. The 'real world' is full of objects. Take a Door for an example, the door needs to be opened and closed, and you pass message by turning its knob. The same message (like turning knob) will have different meanings when you apply to different object. If you turn the knob of radio it will act differently than door, same as with window and desk. But all of them have the same function called 'open' but different behaviour. A new door with a stained glass window inherits most of its quality from a standard door. When you use a door, you usually do not care about the latch or hinge, construction features, and you don't have access to the interior working of the knob or what may be written on the inside of the door panel.
Basic principles of object oriented programming are