Why interfaces?

We should almost always extract interfaces from your service classes because:

  • We should use dependency injection to load and compose implementations: to avoid the need of manually constructing chains of dependent objects and/or to be able to release implementation changes without rebuilding the entire solution, if dependencies are dynamically loaded.
  • We should isolate and test client callers and for this purpose we need mocking; mocking is a lot easier if the call is performed through an interface.
  • Rarely for polymorphism (although this might be their most obvious use): only if really, really needed – I’d say we should always consider composition first; thst would probably save us from much unforeseen trouble!
Advertisements

About Sorin Dolha

My passion is software development, but I also like physics.
This entry was posted in Development and tagged , , , . Bookmark the permalink.

Add a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s