Oops Key Points

Why Interface Use?
  1. Interfaces allow you to define/create a common structure for your classes – to set a standard for objects.
  2. An interface allows different objects to interact easily.
  3. Multiple implementations of same stuff.
  4. Interfaces are great when you have multiple coders working on a project – you can set up a loose structure for programmers to follow and let them worry about the details.
When Interface Use?
  1. When you know what methods a class should have but you are not sure what the details will be.
  2. When you want to quickly map out the basic structures of your classes to serve as a template for others to follow – keeps the code-base predictable and consistent.
When to prefer an Abstract class
  1. When we have the requirement of a class that contains some common properties or methods with some common properties whose implementation is different for different classes, in that situation, it's better to use Abstract Class then Interface.
  2. Abstract classes provide you the flexibility to have certain concrete methods and some other methods that the derived classes should implement. On the other hand, if you use interfaces, you would need to implement all the methods in the class that extends the interface. An abstract class is a good choice if you have plans for future expansion.
Why do we use getters and setters?
 Getters and setters encapsulate the fields of a class by making them accessible only through its  public methods and keep the values themselves private. That is considered a good OO principle.


Comments