Thursday, 25 July 2019

Object Oriented Programming

Building blocks of OOP:
  • Abstraction:
    • Showing the essential details by hiding the complexity.
    • In Java, achieved by Interfaces, Abstract classes.
  • Encapsulation:
    • Hiding the information. Can be field level or behavioural level.
    • In Java, achieved by access specifiers.
  • Inheritance:
    • Inhering properties, methods of another class to avoid code duplication.
    • In Java, achieved Extending a class or implementing any interface.
  • Polymorphism:
    • Allows the actual object to be decided at runtime, basically a subclass/interface can stand in for super class.
    • In Java, achieved Extending a class or implementing any interface.
SOLID Principles
  • Single Responsibility Priniciple
    • One class should own a single responsibilty.
  • Open-Closed Priniciple
    • classes should be open for extension, closed for modification.
    • Can be achieved by inheritance.
  • Liskov Substitution Principle
    • When you inherit a class, you should be able to substitute super class methods on sub class methods without any hussle.
  • Interface segregation Principle
    • Seggregate the interfaces in a way client can use.
  • Dependency injection Principle
    • High level module should not depend on low level module.
Other OOP principles:
  • Favor composition over inheritence.
  • Program to an interface not implementation.
  • DRY: Donot repeat yourself

No comments:

Post a Comment