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

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);
}
主站蜘蛛池模板: 宜城市| 大洼县| 招远市| 鄂伦春自治旗| 鲁山县| 佛坪县| 定陶县| 白水县| 涞水县| 苍山县| 化州市| 会宁县| 望奎县| 郁南县| 甘洛县| 三穗县| 天津市| 承德市| 承德市| 沙雅县| 云梦县| 济源市| 江西省| 海盐县| 永修县| 平和县| 曲沃县| 清徐县| 石泉县| 罗田县| 朝阳市| 惠东县| 鹿泉市| 宁津县| 车险| 固安县| 澄城县| 柳林县| 闽清县| 景洪市| 信宜市|