Sunday, December 1, 2019

Object-Oriented Design Principles (OODP)



1. DRY (Don't repeat yourself) : Don't duplicate code reusability is the best approach.

2. Encapsulate What Changes: Use the access specified wisely and not everything should be public (class/object/variable).

3. Open Closed Design Principle: Classes, methods or functions should be Open for extension (new functionality) and Closed for modification.

4. Single Responsibility Principle (SRP) : There should not be more than one reason for a class to change, or a class should always handle single functionality.

5. Dependency Injection or Inversion principle

6. Favor Composition over Inheritance : Always favor composition over inheritance. Composition allows changing the behavior of a class at run-time by setting property during run-time and by using Interfaces to compose a class we use polymorphism which provides flexibility to replace with better implementation at any time.

7. Liskov Substitution Principle (LSP) : Methods or functions which use the superclass type must be able to work with the object of subclass without any issue.

8. Interface Segregation Principle (ISP) : A client should not implement an interface if it doesn't use that. This happens mostly when one interface contains more than one functionality, and the client only needs one functionality and no other.

9. Programming for Interface not implementation 

10. Delegation principles : Don't do all stuff by yourself,  delegate it to the respective class. Classical example of delegation design principle is equals() and hashCode() method in Java.

No comments:

AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...