Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

13. Programming Principles > Dependency Inversion

Dependency Inversion

DEPENDENCY INVERSION is one of the most effective ways of ensuring that your class hierarchies are open for extension but closed for modification. There are three basic guidelines for implementing dependency inversion. (They’re sometimes described as “rules”, but no design principles are, or should be, unbreakable, and these perhaps more than most!)


Dependency Inversion

image

No client class should depend on a low-level class. Instead, they should both depend on an abstraction.


1 BEWARE OF CLASS MEMBERS DEFINED AGAINST A CONCRETE CLASS

Whether you’re considering properties or variables, be sensible about this one—it’s impossible to implement completely. Somewhere or other, you have to create a String or Int16 (which are concrete classes, after all) or you’ll never be able to do anything! But implementing a concrete class makes you vulnerable to changes made to it, and that leads to fragile code, so... beware.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint