AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Tuesday 27 November 2018

Dependency inversion Principle

Dependency Inversion principle is a part of SOLID principle. It was given by Bob Martin, who is founder of SOLID principles.

Bob's Definition

  • High level module should not be dependent on lower level modules. Both should dependent on abstraction.
  • Abstraction should not dependent on details. Details should be dependent on abstraction.

Copy Problem
One of the examples given by Bob Martin is a Copy Problem.
There is copy program which is copy from keyboard and write to a printer. So its a simple problem but problem raised when what happened when it need to write on disk.
So the problem of above problem can be given by dependency inversion. where implementation of Reader(IReader Interface) and Writer(IWriter Interface) are the part of copy program(Higher level module). Keyboard Reader(Lower level modules) and Printer writer(Lower level modules) is dependent on Reader and writer respectively.
Now, If disk writer is need to be added it can be include in Writer side.


 

0 comments :

Post a Comment

  • Popular Posts
  • Comments