Coupling

Synonymcouplingdegreegenerallyreferstocoupling

Introduction

Coupling(English:Coupling,dependency,orCouplingforceorCoupling)isasoftwaremetric,whichreferstothedegreeofdependenceoninformationorparametersbetweenmodulesandmodulesinaprogram.

Cohesionisaconceptoppositetocoupling.Generallyspeaking,lowcouplingmeanshighcohesion,andviceversa.CouplingandcohesionarebothproposedbyLarryConstantinewhoproposedtheconceptofstructureddesign.Lowcouplingisacharacteristicofwell-structuredprograms,andthereadabilityandmaintainabilityoflow-couplingprogramswillbebetter.

Classificationofcoupling

Couplingcanbelowcoupling(orloosecoupling)orhighcoupling(ortightcoupling).Herearesomecategoriesofcoupling,arrangedinorderfromhightolow:

  • Contentcoupling(contentcoupling,thehighestdegreeofcoupling)

  • Itisalsocalledpathologicalcouplingwhenamoduledirectlyusestheinternaldataofanothermodule,ortransfersitintoanothermodulethroughanabnormalentry.

  • Sharedcoupling/commoncoupling

  • Alsoknownasglobalcoupling.Thecouplingbetweenthemodulesinteractingwiththecommondataenvironment.Thecomplexprogramofpubliccouplingincreaseswiththeincreaseofthenumberofcouplingmodules.

  • Externalcoupling

  • Itoccurswhentwomodulesshareanadditionaldataformat,communicationprotocolorThedeviceinterfaceisbasicallyrelatedtothecommunicationbetweenthemoduleandexternaltoolsandequipment.

  • Controlcoupling

  • Whenamodulecallsanothermodule,itpassescontrolvariables(suchasSwitch,flag,etc.),themodulatedmoduleselectivelyexecutesafunctionintheblockthroughthevalueofthecontrolvariable;

  • featurecoupling/stampcoupling

  • p>

  • Alsoknownasdatastructurecoupling,itmeansthatseveralmodulesshareacomplexdatastructure,suchasarraynames,recordnames,andfilenamesinhigh-levellanguages.Thesenamesaretags.Infact,whatispassedistheaddressofthisdatastructure;

  • Datacoupling/datacoupling

  • referstothemoduleSharingdatabypassinginvalues,eachdataisthemostbasicdata,andonlysharingthesedata(forexample,passinganintegertothefunctionthatcalculatesthesquareroot).

  • Messagecoupling(messagecouplingisthecouplingwiththelowestdegreeofcouplingbesidesnocoupling)

  • YoucanusethefollowingTherearetwowaystoachievethis:decentralizationofstate(forexample,inobjects),andcommunicationbetweencomponentsusingincomingvalues​​ormessagepassing(computerscience).

  • Nocoupling:Themoduledoesnotexchangeinformationwithothermodulesatall.

Object-orientedprogramming

  • Subclasscoupling

  • Describetherelationshipbetweenthechildclassandtheparentclass.Thechildclassislinkedtotheparentclass,buttheparentclassisnotlinkedtothechildclass.

  • temporalcoupling

  • Thetwoactionsarepackagedinonemoduleonlybecausetheyhappenatthesametime.

Laterresearchhasproposedmanydifferentlevelsofcoupling,andusedtoevaluatetheimplementationdegreeofvariousmodularlawsinpractice.

Disadvantages

Thetightlycoupledsystemhasthefollowingdisadvantagesinthedevelopmentphase:

  1. Modificationsofonemodulewillproducerippleeffects,othersThemodulealsoneedstobemodifiedaccordingly.

  2. Becauseofthedependenciesbetweenmodules,thecombinationofmoduleswillrequiremoreeffortandtime.

  3. Sinceamodulehasmanydependentmodules,thereusabilityofthemoduleislow.

Improvementmethod

Functionaldesignisamethodthatcanreducecoupling.ThismethodtriestolimittheresponsibilityofeachmodulefromafunctionalperspectiveAffairs.BetweenthecategoriesAandB,ifanyofthefollowingsituationsexists,thecouplingbetweenthetwowillbeimprovedSex:

  • AThereisanattributeofreferencecategoryB(TheformofthisattributeiscategoryB)

  • ACalltheserviceprovidedbytheobjectB

  • AThereisamethodthatreferstothecategoryB(thismethodwillreturnaphysicalpropertyofthecategoryB)

  • AisasubcategoryofcategoryB.

Loosecouplingreferstotwomodulesrelatedtoeachother,theinterfaceofwhichisasimpleandstableinterface,anditsinterfacehasnothingtodowiththeinternalimplementationofanymodule(Referenceinformationhiding).

SystemslikeCORBAorComponentObjectModelallowanobjecttointeractwithanotherobjectwithoutknowinghowtheotherobjectisimplemented.Suchsystemsevenallowanobjecttointeractwithobjectswritteninotherlanguages.

Couplingandcohesion

Thetwotermscouplingandcohesionoftenappeartogethertoindicatethecharacteristicsthatanidealmoduleneeds,thatis,lowcouplingandHighcohesion.Couplingfocusesonthedependencebetweendifferentmodules,whilecohesionfocusesontherelationshipbetweendifferentfunctionsinamodule.Lowcohesionmeansthatthereisnorelationshipbetweenthefunctionsinamodule,andproblemsoftenoccurwhenthemoduleisexpanded.

Relateditems

  • Dependencyhell

  • Outgoingcoupling

  • Cohesion(ComputerScience)

  • ListofObject-OrientedProgrammingTerms

  • make

  • Staticprogramanalysis

  • Inversionofcontrol

  • Looselycoupled

Related Articles
TOP