What is "class coupling", please?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald S. Cook

    #1

    What is "class coupling", please?


    In trying to figure out how to make function
    MedicineClass.A pplyMedicinePri ceChanges perform better, I ran Code Analysis
    and got the following:

    *************** *************** *************** *************** *************** ***************
    Warning 1677 CA1506 : Microsoft.Maint ainability :
    'MedicineClass. ApplyMedicinePr iceChanges(Prog ramMedicinePric e, String, Guid,
    Decimal)' is coupled with 34 different types from 9 different namespaces.
    Rewrite or refactor the method to decrease its class coupling, or consider
    moving the method to one of the other types it is tightly coupled with. A
    class coupling above 40 indicates poor maintainability , a class coupling
    between 40 and 30 indicates moderate maintainability , and a class coupling
    below 30 indicates good maintainability .
    D:\Win\FRC.COW. Feedyard.DAL\FR C.COW.Feedyard. DAL\Business
    Classes\Medicin eClass.cs 514 FRC.COW.Feedyar d.DAL
    *************** *************** *************** *************** *************** ***************

    Does anyone have any idea what all this means?

    Thanks if you have any thoughts. Below is the function for reference.

    Ron

    ------------------------------------------------------------------------------------------------------------------------

    public void ApplyMedicinePr iceChanges(Prog ramMedicinePric e
    ProgramMedicine Price, string AddOrEdit, Guid LoginId, Decimal
    OldPriceIfWasEd ited, void =, void 0) {
    if ((ProgramMedici nePrice.Program MedicinePriceDa te.Date <
    DateTime.Today. Date)) {
    // If equal to today or later, then we don't do any retro
    pricing.
    // We already know date is not earlier than start of current
    billing period (caught in validation).
    // Capture old price for when issuing credits.
    Decimal OldPrice;
    switch (AddOrEdit) {
    case "Add":
    OldPrice = GetOldPrice(Pro gramMedicinePri ce);
    break;
    case "Edit":
    OldPrice = OldPriceIfWasEd ited;
    break;
    }
    // Get day before next date in database as will be the range end
    date.
    DateTime RangeEndDate = GetRangeEndDate (ProgramMedicin ePrice);
    // Has charge been invoiced?
    // Then as long as the LotStatus <cls, rej, pnd, or shp then
    go total up numbers from AnimalMedicine & LotPenMedicine.
    // If the LotStatus is CLS or SHP, then the charges have already
    been invoiced and the individual charge is not repriced.
    Charge _Charge;
    ChargeClass _ChargeClass = new ChargeClass();
    // AnimalMedicine.
    *************** *************** *************** *************** *************** *************** *************** ***************
    IList _AnimalMedicine List = From;
    am;
    dc.AnimalMedici nes;
    Where;
    (ProgramMedicin ePrice.ProgramI d
    & ((am.Animal.Lot Pen.Lot.Lookup. LookupValue !=
    "CLS")
    & ((am.Animal.Lot Pen.Lot.Lookup. LookupValue !=
    "REJ")
    & ((am.Animal.Lot Pen.Lot.Lookup. LookupValue !=
    "PND")
    & ((am.Animal.Lot Pen.Lot.Lookup. LookupValue !=
    "SHP")
    & am.AnimalMedici neIsCharged)))) ) = true;
    (ProgramMedicin ePrice.Medicine Id
    & ((am.AnimalMedi cineDateTime >=
    ProgramMedicine Price.ProgramMe dicinePriceDate )
    & ((am.AnimalMedi cineDateTime <= RangeEndDate)
    & am.Animal.LotPe n.Lot.ProgramId ))) = true;
    am.MedicineId = true;
    Group;
    By;
    LotPenId = am.Animal.LotPe nId;
    Into;
    SumOfDosage = Sum(am.AnimalMe dicineDosage);
    switch (LotPenId) {
    case SumOfDosage:
    ToList();
    // Loop through summed LotPenId and Dosage records and
    create Charge entries.
    for (int i = 0; (i
    <= (_AnimalMedicin eList.Count - 1)); i++) {
    // For each sum of medicines used in a LotPen, enter
    a DEBIT charge with the NEW amount.
    _Charge = new Charge();
    _Charge.ChargeD ate = DateTime.Today. Date;
    _Charge.ChargeD ollars =
    (Decimal.Parse( ProgramMedicine Price.ProgramMe dicinePriceDoll ars) *
    _AnimalMedicine List[i]["SumOfDosag e"]);
    _Charge.LotPenI d =
    _AnimalMedicine List[i]["LotPenId"];
    _Charge.ChargeC odeId =
    ProgramMedicine Price.Medicine. ChargeCodeId;
    _ChargeClass.Ad dCharge(_Charge , LoginId);
    // For each sum of medicines used in a LotPen, enter
    a CREDIT charge with the OLD amount.
    _Charge = new Charge();
    _Charge.ChargeD ate = DateTime.Today. Date;
    _Charge.ChargeD ollars = (0
    - (OldPrice *
    _AnimalMedicine List[i]["SumOfDosag e"]));
    // Make amount NEGATIVE for the credit using OLD
    price.
    _Charge.LotPenI d =
    _AnimalMedicine List[i]["SumOfDosag e"];
    _Charge.ChargeC odeId =
    ProgramMedicine Price.Medicine. ChargeCodeId;
    _ChargeClass.Ad dCharge(_Charge , LoginId);
    }
    //
    *************** *************** *************** *************** *************** *************** *************** *************** *************** *
    // LotPenMedicine.
    *************** *************** *************** *************** *************** *************** *************** ***************
    IList _LotPenMedicine List = From;
    lpm;
    dc.LotPenMedici nes;
    Where;
    (ProgramMedicin ePrice.ProgramI d
    & ((lpm.LotPen.Lo t.Lookup.Lookup Value !=
    "CLS")
    & ((lpm.LotPen.Lo t.Lookup.Lookup Value !=
    "REJ")
    & ((lpm.LotPen.Lo t.Lookup.Lookup Value !=
    "PND")
    & ((lpm.LotPen.Lo t.Lookup.Lookup Value !=
    "SHP")
    & lpm.LotPenMedic ineIsCharged))) )) = true;
    (ProgramMedicin ePrice.Medicine Id
    & ((lpm.LotPenMed icineDateTime >=
    ProgramMedicine Price.ProgramMe dicinePriceDate )
    & ((lpm.LotPenMed icineDateTime <=
    RangeEndDate)
    & lpm.LotPen.Lot. ProgramId))) = true;
    lpm.MedicineId = true;
    Group;
    By;
    LotPenId = lpm.LotPen.LotP enId;
    Into;
    SumOfDosage = Sum(lpm.LotPenM edicineDosage);
    switch (LotPenId) {
    case SumOfDosage:
    ToList();
    // Loop through summed LotPenId and Dosage
    records and create Charge entries.
    for (int i = 0; (i
    <= (_LotPenMedicin eList.Count - 1));
    i++) {
    // For each sum of medicines used in a
    LotPen, enter a CREDIT charge with the NEW amount.
    _Charge = new Charge();
    _Charge.ChargeD ate = DateTime.Today. Date;
    _Charge.ChargeD ollars =
    (Decimal.Parse( ProgramMedicine Price.ProgramMe dicinePriceDoll ars) *
    _LotPenMedicine List[i]["SumOfDosag e"]);
    _Charge.LotPenI d =
    _LotPenMedicine List[i]["LotPenId"];
    _Charge.ChargeC odeId =
    ProgramMedicine Price.Medicine. ChargeCodeId;
    _ChargeClass.Ad dCharge(_Charge , LoginId);
    // For each sum of medicines used in a
    LotPen, enter a DEBIT charge with the OLD amount.
    _Charge = new Charge();
    _Charge.ChargeD ate = DateTime.Today. Date;
    _Charge.ChargeD ollars = (0
    - (OldPrice *
    _LotPenMedicine List[i]["SumOfDosag e"]));
    // Make amount NEGATIVE for the debit using
    OLD price.
    _Charge.LotPenI d =
    _LotPenMedicine List[i]["SumOfDosag e"];
    _Charge.ChargeC odeId =
    ProgramMedicine Price.Medicine. ChargeCodeId;
    _ChargeClass.Ad dCharge(_Charge , LoginId);
    }
    //
    *************** *************** *************** *************** *************** *************** *************** *************** *************** *
    break;
    }
    break;
    }
    }
    }



  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: What is &quot;class coupling&quot;, please?

    Ronald S. Cook wrote:
    In trying to figure out how to make function
    MedicineClass.A pplyMedicinePri ceChanges perform better, I ran Code
    Analysis and got the following:
    >
    *************** *************** *************** *************** *************** ***************
    >
    Warning 1677 CA1506 : Microsoft.Maint ainability :
    'MedicineClass. ApplyMedicinePr iceChanges(Prog ramMedicinePric e, String,
    Guid, Decimal)' is coupled with 34 different types from 9 different
    namespaces. Rewrite or refactor the method to decrease its class
    coupling, or consider moving the method to one of the other types it is
    tightly coupled with. A class coupling above 40 indicates poor
    maintainability , a class coupling between 40 and 30 indicates moderate
    maintainability , and a class coupling below 30 indicates good
    maintainability .
    Try read:


    Arne

    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: What is &quot;class coupling&quot;, please?

      Ronald S. Cook wrote:
      In trying to figure out how to make function
      MedicineClass.A pplyMedicinePri ceChanges perform better, I ran Code
      Analysis and got the following:
      >
      *************** *************** *************** *************** *************** ***************
      Warning 1677 CA1506 : Microsoft.Maint ainability :
      'MedicineClass. ApplyMedicinePr iceChanges(Prog ramMedicinePric e,
      String, Guid, Decimal)' is coupled with 34 different types from 9
      different namespaces. Rewrite or refactor the method to decrease its
      class coupling, or consider moving the method to one of the other
      types it is tightly coupled with. A class coupling above 40 indicates
      poor maintainability , a class coupling between 40 and 30 indicates
      moderate maintainability , and a class coupling below 30 indicates
      good maintainability .
      D:\Win\FRC.COW. Feedyard.DAL\FR C.COW.Feedyard. DAL\Business
      Classes\Medicin eClass.cs 514 FRC.COW.Feedyar d.DAL
      *************** *************** *************** *************** *************** ***************
      >
      Does anyone have any idea what all this means?
      >
      Thanks if you have any thoughts. Below is the function for reference.
      Any number of other metrics (lines of code, complexity, branches) should be
      telling you to split the method into multiple smaller ones, each handling a
      specific well-defined subtask.
      >
      Ron

      Comment

      Working...