Direct or traditional approach: Object creates its own dependencies.
Inverted approach (inversion of control): Dependencies are created outside the object. This responsibility is given to someone else.
Example 1 (Direct approach):
We have a service named EmailService
which is an implementation of INotificationService
.
public interface INotificationService
{
void SendNotification();
}
public class EmailService : INotificationService
{
public void SendNotification()
{
// code to send notification
}
}
OrderService
need to use the INotificationService
.