Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 777 Bytes

5_DIP_code_problem.md

File metadata and controls

15 lines (11 loc) · 777 Bytes

Example code showing tightly coupled dependencies

class CustomerService {
  void ActivateLogin(Customer customer) {
    var log = new TextFileLogger();
    log.logEvent("Customer " + customer.name + " is being activated");

    var emailService = new MailchimpEmailService();
    emailService.SendWelcomeEmail(customer);
  }
}

The CustomerService class is now tightly coupled to the TextFileLogger and MailchimpEmailService implementation. Why is this not ideal? What if we decide to change to another logger? Or we stop using Mailchimp for sending mails down the line? We will have to make code changes. How can we decouple this mess?

« back to readme.md | view the refactored code »