- 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);
}
推薦閱讀
- Deploying Node.js
- VMware View Security Essentials
- TensorFlow Lite移動端深度學習
- Building a Game with Unity and Blender
- 三維圖形化C++趣味編程
- UI智能化與前端智能化:工程技術、實現方法與編程思想
- Mastering Python High Performance
- MySQL數據庫管理與開發(慕課版)
- 零基礎學Java程序設計
- 編程與類型系統
- Getting Started with React Native
- Node學習指南(第2版)
- SQL Server 2016 從入門到實戰(視頻教學版)
- 交互式程序設計(第2版)
- Spark技術內幕:深入解析Spark內核架構設計與實現原理