官术网_书友最值得收藏!

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);
}
主站蜘蛛池模板: 滦南县| 安塞县| 无锡市| 玉林市| 新昌县| 双流县| 当涂县| 阿鲁科尔沁旗| 灵川县| 达日县| 靖安县| 石柱| 云龙县| 武邑县| 炉霍县| 霍林郭勒市| 射洪县| 泽州县| 建阳市| 丹江口市| 隆尧县| 邹平县| 泽库县| 榆社县| 白城市| 瑞安市| 双辽市| 洛宁县| 新巴尔虎右旗| 交口县| 武川县| 栾城县| 花莲县| 尼勒克县| 吴旗县| 新沂市| 石阡县| 松潘县| 湖州市| 加查县| 渑池县|