- C# and .NET Core Test Driven Development
- Ayobami Adewole
- 150字
- 2021-06-25 22:00:27
Loose coupling
Loose coupling is the direct opposite of tight coupling. This is a good object-oriented programming practice of separation of concerns by allowing components to have little or no information of the internal workings and implementation of other components. Communication is done through interfaces. This approach allows for an easy substitution of components without many changes to the entire code base. The sample code in the Tight coupling section can be refactored to allow loose coupling:
//The dependency injection would be done using Ninject
public ISmppManager smppManager { get; private set; }
public void SendSMS()
{
smppManager.SendMessage("0802312345","Hello", "John");
}
public class SmppManager
{
private string sourceAddress;
private SmppClient smppClient;
public SmppManager()
{
smppClient = new SmppClient();
smppClient.Start();
}
public void SendMessage(string recipient, string message, string senderName)
{
// send message using referenced library
}
}
public interface ISmppManager
{
void SendMessage(string recipient, string message, string senderName);
}
推薦閱讀
- Java Web開發學習手冊
- Spring技術內幕:深入解析Spring架構與設計
- Interactive Data Visualization with Python
- The Computer Vision Workshop
- 微信公眾平臺開發:從零基礎到ThinkPHP5高性能框架實踐
- OpenStack Orchestration
- ExtJS高級程序設計
- 響應式Web設計:HTML5和CSS3實戰(第2版)
- Django實戰:Python Web典型模塊與項目開發
- 從零開始學Android開發
- OpenCV 3計算機視覺:Python語言實現(原書第2版)
- Clojure Polymorphism
- Puppet:Mastering Infrastructure Automation
- Java核心技術卷I基礎知識(原書第9版)
- Java EE 8 Development with Eclipse