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

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);
}
主站蜘蛛池模板: 金山区| 方城县| 保定市| 盐津县| 清新县| 鄱阳县| 武清区| 团风县| 洱源县| 佛学| 彰武县| 九江市| 湾仔区| 常熟市| 博兴县| 贵溪市| 江阴市| 大厂| 策勒县| 同仁县| 卓尼县| 沾益县| 乌兰浩特市| 旌德县| 广昌县| 遂宁市| 仪征市| 无极县| 丰顺县| 大洼县| 垣曲县| 金寨县| 旌德县| 淅川县| 遂平县| 个旧市| 阳山县| 长寿区| 武鸣县| 泸州市| 德阳市|