Skip to content

Latest commit

 

History

History
61 lines (33 loc) · 2.26 KB

oop.md

File metadata and controls

61 lines (33 loc) · 2.26 KB

OBJECT ORIENTED PROGRAMMING

Pillars of Object Oriented Programming

  • Inheritance
  • Abstraction
  • Polymorphism
  • Encapsulation

Classes

  • A class is template for creating objects. It has properties (sometimes with default values) which describes the state of an object and methods (implementation code) which describes the behavior of an object.

Objects

  • An object is an instance (instance means runtime object) of a class having properties and methods.

Properties/Attributes

  • A property is a variable defined inside a class. Each object has it's own copy of the property.

Methods/Behaviors

  • A method is a function/routine defined inside a class. Each object has it's own copy of the property.

Static Properties and Methods

  • A static property is a variable that can be accessed without creating an instance of a class.
  • A static method is a function that can be accessed without creating an instance of a class.

Interfaces

  • An interface is like a contract which defines a set of methods (does not include implementation) that a class must include. We only define abstract methods in an interface and the class that implements this interface must define it's body. Interfaces can't be instantiated.

Abstract Classes

  • An abstract class is a type of class that can't be instantiated and it can also contain abstract methods. They are mostly used for inheritance.

Inheritance

  • Inheritance is a process where a child class inherits all the properties and methods of a parent class.

Abstraction

  • Abstraction is a process of hiding implementation details. It can be implemented using interfaces and abstract classes.

Polymorphism

  • Polymorphism is the ability of an object to take on many forms. method overloading and method overriding are ways of implementing polyporphism.

Method Overloading

  • Methods with same name but different parameters.

Method Overriding

  • When we redefine a method with different implementation logic which is already available in the parent class.

Encapsulation

  • Encapsulation is a process of data hiding. It can be implemented by defining private properties and public getters and setters for the properties so these properties cannot be directly accessed from outside the class.