OOPS is a programming methodology which organizes the programs as Object and data, rather than action and logic. This shift from action-based to the object-based is to bind the data and the functions together and
OOPS is a programming methodology which organizes the programs as Object and data, rather than action and logic. This shift from action-based to the object-based is to bind the data and the functions together and to restrict other parts of the code (unwanted code) from accessing them.
OOPS provide the below advantages over procedural structure:
- Data Security: Methods can access data only if they have access.
- Modularity: Action and Logics are stored in various classes. So adding or removing features will be easy. Even multiple users can work on the same application as the code is modular and it will not have interdependency.
- Reuse of Code: There would be times when you would write the same code over and over with OOPS you could write the code once and refer the logic whenever required.
- Faster Development: Code reusability and modularity lets team to work simultaneously and reuse code block to reduce development time.
- Easy to Maintain: As the code is modular in nature upgrades for the application will require fewer code changes.
Building Blocks Of OOPS Model:
A class is like a container that can store properties, fields, events, method, etc to perform a defined activity. You can create your own custom data types with class. To access the data within the container you would need to create an object of the container. The Class is the core foundation of OOPS.
If a class is a container then the object is a way by which we can access the data associated with the class. An object is an instance of a class. When we create an object for a class, the
Encapsulation is a process of enclosing/binding Member variables and Member Functions together within a single package usually called a class. As a result, we are able to hide the implementation details of a class from a client function.
If Encapsulation is a process of enclosing data into packages, then Abstraction is a way of making relevant information visible by hiding the background details. For implementing Abstraction we use access Specifiers.
Access Specifiers: Define the scope and visibility of a class member. The following are the list of access specifiers in c#.
- Public: It allows a class to expose its member variables and functions to other functions and objects. i.e public member can be accessed from outside the class.
- Private: Only functions of the same class can access its private members.
- Protected: It lets a child class access the member variables and functions of its base class and helps in implementing inheritance.
- Internal: It allows a class to expose its member variables and functions to other functions and objects wit in the same assembly.
- Protected internal: It allows a class to hide its member variables and functions from other class objects and functions, except a child class within the same application.
It is a process of hiding the internal structure of an object from the rest of the program. For implementing data hiding we use Abstraction and Encapsulation.