A programming model which is mainly organized around the objects is called Object-Oriented Programming or the Programming named OOP.
There are five basic pillars or concepts in OOP.
- Encapsulation
- Data Hiding
- Specialization
- Polymorphism
- Division of Responsibility
Encapsulation is a process of binding data members (variables, properties) and member functions (methods) together.
Data Hiding refers to the class’s internal data is not accessible from outside the class.
Specialization allows you to establish hierarchical relationships among your classes.
Polymorphism is the process in which an object or function takes different forms.
Division of Responsibility reflects the program design and how will work in terms of the development of the team.
All these pillars/concepts have advantages and disadvantages in development.
The advantages and disadvantages result from the mode of interconnection and development.
An advantage of encapsulation is the property of hiding the internals of the object or allowing access to it through only member function protects objects integrity by preventing users from setting the internal data or the component.
This allows us to avoid an invalid or inconsistent state of the object.
The inheritance advantage is code re-usability.
An advantage of polymorphism is the use of the overload method.
Let see an example with polymorphism:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Sum { public int Add(int number_1,int number_2) { return(number_1+number_2); } public int Add(double number_1,double number_2) { return(number_1+number_2); } } class Program { public static void Main() { Sum mysum_obj=new Sum(); Console.WriteLine("Sum of two integer number is "+mysum_obj.Add(1,2)); Console.WriteLine("Sum of two float number is "+mysum_obj.Add(1.1,2.2)); } } |