How to avoid OO designs violate the Dependecy Inversion Principle?

How to avoid OO designs violate the Dependecy Inversion Principle?

1. No varible should hold a reference to a concrete class.
      If you use new, you'll be holding a reference to a concrete class. Use a factory to get around that.

2. No class should derive from a concrete class.
      If you derive from a concrete class, you're depending on a concrete class. Derive from an abstraction, like an interface or an abstraction class.

3. No method should override an implemented method of any of its base classes.
      If you override an implented method, then your base class wasn't really an abstraction to start with. Those methods implemented in the base class are meant to be shared by all your subclasses.

你可能感兴趣的:(How to avoid OO designs violate the Dependecy Inversion Principle?)