Object-oriented programming (OOP) is a programming paradigm in which programs are considered as a collection of objects and these objects are used to design and build applications. An object is nothing but a model of the concepts, processes or things in the real world that are meaningful to the application. OOP provides many concepts like inheritance, abstraction, data binding, polymorphism etc. Simula is considered as the first object-oriented programming language. Significant object-oriented languages are C++, C#, Java, PHP, Python, Ruby, Delphi, Perl, Objective-C, Swift, Common Lisp and Smalltalk.
An object is a block of memory that has been allocated and configured in a class. There can be many objects in a class and can be stored in either a named variable or in an array or collection. We can say that an object is a self-contained component consists of properties and methods required to make a particular type of data useful. Objects are used to interact with one another to build applications. Perfect use of objects makes it easier to develop, upgrade and maintain the application. For example, in a inventory management application, we would have a purchase object, a order object and a sale object. Its desirable qualities are Modularity, Information Hiding and Code Reusability.
Main characteristics of object oriented programming (OOP) are-
The advantages of using Object Oriented Programming (OOP) are-
A class is a set of instructions to build a specific type of object. Class contains the data members and member functions. Data need to be well defined in a class. It is to be noted that following the concept of single responsibility, each class should be designed to perform only one task. Many classes should be used to build an entire application.
The keyword class in C# shows that we are going to define a new class. A class is stored in a heap. Classes can be inherited which means a class can create a subclass.
Abstract class is a class that cannot be instantiated into objects, it exists extensively for the purpose of inheritance and it must be inherited. It may contain one or more abstract methods. Abstract method is a method that is declared but does not contain any implementation.
Abstract classes should be used:
While designing large functional units
For the objects that are closely related
If we want to build multiple versions of our component
While providing common functionality among all implementations of the component
Public Access Modifier
It states that there are no restrictions on accessing public members of a class.
Private Access Modifier
It states that the scope of private members of the class will be limited to only that particular class. We cannot explicitly declare a class as Private but if we do not specify any access modifier to the class, it is assumed as Private.
Protected Access Modifier
It states that protected members of the class are accessible from within the class in which they are declared and from any class which is derived from the class that declares protected members.
Abstraction
It is used to hide all the data except the relevant data regarding an object improve efficiency
It is implementation oriented
Its focus is on the interface means the outer look of the object
Encapsulation
It is used to wrap code and data together in a single unit
It is design oriented.
It does not allow other objects or methods to look into the properties and behaviour of any object