Design Patterns: Inversion of Control

Please see my other Design Pattern articles.

Providing flexibility into the domain by abstracting implementation.


Using abstraction between concrete and class implementation, avoid tightly-coupled classes, which leads to changes in once class to ripple throughout your application.
One method of doing this is the Inversion of Control design pattern which allows the class calling the behavior to be ignorant of its details, or, “loosely-coupled.”

To illustrate this pattern, I’ll begin with the abstraction – an interface through which my class will interact to call Pay().
This interface is where I’ll define just the signature of the behavior I wish to use, but I won’t provide the implementation.


Now I’ll provide the implementation of Pay(). However, remember that my class which will use this behavior won’t interact with this classes directly.


Here’s where the magic begins. My CustomerPayment class will act as a conduit between user of the behavior and its implementation.
Notice that it uses an interface instance to call the behavior.

With wrapper of abstraction completed, I will now use the behavior.


The benefit of using this design pattern is that if the implementation details of the behavior change, it won’t affect any other classes.5-inversion-of-control

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s