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

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);
}
主站蜘蛛池模板: 华坪县| 城口县| 宜宾县| 通州市| 莒南县| 休宁县| 英超| 灵丘县| 南城县| 游戏| 岑巩县| 文安县| 贵州省| 庄河市| 德安县| 永丰县| 佳木斯市| 金湖县| 浮山县| 贺州市| 绵阳市| 内黄县| 天气| 富阳市| 张家界市| 册亨县| 肇源县| 乐都县| 平顺县| 台东市| 长治市| 黄大仙区| 札达县| 晋城| 栾城县| 扎鲁特旗| 抚顺县| 揭西县| 湘乡市| 颍上县| 区。|