- 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);
}
推薦閱讀
- C語言程序設(shè)計教程
- Python程序設(shè)計教程(第2版)
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- Apache Spark 2.x Machine Learning Cookbook
- Mastering Julia
- Java程序設(shè)計:原理與范例
- Building RESTful Python Web Services
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- 21天學通C++(第5版)
- Appcelerator Titanium:Patterns and Best Practices
- 計算機組裝與維護(第二版)
- Implementing Microsoft Dynamics NAV(Third Edition)
- 微信小程序開發(fā)邊做邊學(微課視頻版)
- C++服務(wù)器開發(fā)精髓
- 自己動手構(gòu)建編程語言:如何設(shè)計編譯器、解釋器和DSL