Everything is OOP is grouped as self sustainable objects; hence you gain re-usability by means of four object oriented programming concepts.

Advantages of OOP
Bundling code into individual software objects provides a number of benefits, including:

  1. Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.
  2. Information-hiding: By interacting only with an object’s methods, the details of its internal implementation remain hidden from the outside world.
  3. Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code.
  4. Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.

Concepts in OOP

  1. Class
  2. Object
  3. Inheritance
  4. Encapsulation or data hiding
  5. Abstraction
  6. Polymorphism

  1. Class
    A class is the blueprint from which individual objects are created.
  2. Object
    Real-world objects share two characteristics: They all have state and behaviour. An object stores its state in fields(variables in some programming languages) and exposes its behaviour through methods (functions in some programming languages).
  3. Inheritance
    Object-oriented programming allows classes to inherit commonly used state and behaviour from other classes. Each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses.

    Sealed Classes:
    The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class. A sealed class cannot also be an abstract class.

  4. Encapsulation or data hiding
    access specifiers determine who can use the definitions that follow. public means the following definitions are available to everyone. The private keyword, on the other hand, means that no one can access those definitions except you, the creator of the type, inside member functions of that type. private is a brick wall between you and the client programmer. If someone tries to access a private member, they’ll get a compile-time error. protected acts just like private, with the exception that an inheriting class has access to protected members, but not private members.
  5. Abstraction
    As per dictionary ‘abstraction is a general idea rather than a specific example”. Putting it in other word; abstraction is an emphasis on the idea, qualities and properties rather than the particulars (a suppression of detail). The importance of abstraction is derived from its ability to hide irrelevant details and from the use of names to reference objects. Abstraction is essential in the construction of programs. It places the emphasis on what an object is or does rather than how it is represented or how it works. Thus, it is the primary means of managing complexity in large programs.
    • Abstract class:
      Abstract classes, which declared with the abstract keyword, cannot be instantiated. It can only be used as a super-class for other classes that extend the abstract class. Abstract class is the concept and implementation gets completed when it is being realized by a subclass. In addition to this a class can inherit only from one abstract class (but a class may implement many interfaces) and must override all its abstract methods/ properties and may override virtual methods/ properties.
    • Interface:
      In summary the Interface separates the implementation and defines the structure, and this concept is very useful in cases where you need the implementation to be interchangeable. Apart from that an interface is very useful when the implementation changes frequently. Some say you should define all classes in terms of interfaces, but I think recommendation seems a bit extreme.

      Interface can be used to define a generic template and then one or more abstract classes to define partial implementations of the interface. Interfaces just specify the method declaration (implicitly public and abstract) and can contain properties (which are also implicitly public and abstract). Interface definition begins with the keyword interface. An interface like that of an abstract class cannot be instantiated.

      If a class that implements an interface does not define all the methods of the interface, then it must be declared abstract and the method definitions must be provided by the subclass that extends the abstract class. In addition to this an interfaces can inherit other interfaces. .Net support multiple implementations, the concept of implicit and explicit implementation provide safe way to implement methods of multiple interfaces by hiding, exposing or preserving identities of each of interface methods, even when the method signatures are the same.

      Theoretically a class emphasis the idea of encapsulation, while an interface emphasis the idea of abstraction (by suppressing the details of the implementation).
      Abstract class Interface
      Interface definition begins with a keyword interface so it is of type interface Abstract classes are declared with the abstract keyword so it is of type class
      Interface has no implementation, but they have to be implemented. Abstract class’s methods can have implementations and they have to be extended.
      Interfaces can only have method declaration (implicitly public and abstract) and fields (implicitly public static) Abstract class’s methods can’t have implementation only when declared abstract.
      Interface can inherit more than one interfaces Abstract class can implement more than one interfaces, but can inherit only one class
  6. Polymorphism
    In OOP the polymorphisms is achieved by using many different techniques named method overloading, operator overloading and method overriding.
    Assume that the Class A implements a virtual method M and classes B and C that are derived from A override the virtual method M. When B is cast to A a call to the method M from A is dispatched to B. Similarly when C is cast to A a call to M is dispatched to C. The decision on exactly which method to call is delayed until runtime.