PC Review


Reply
Thread Tools Rate Thread

What is "class coupling", please?

 
 
Ronald S. Cook
Guest
Posts: n/a
 
      1st Jul 2008

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

******************************************************************************************
Warning 1677 CA1506 : Microsoft.Maintainability :
'MedicineClass.ApplyMedicinePriceChanges(ProgramMedicinePrice, 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\FRC.COW.Feedyard.DAL\Business
Classes\MedicineClass.cs 514 FRC.COW.Feedyard.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 ApplyMedicinePriceChanges(ProgramMedicinePrice
ProgramMedicinePrice, string AddOrEdit, Guid LoginId, Decimal
OldPriceIfWasEdited, void =, void 0) {
if ((ProgramMedicinePrice.ProgramMedicinePriceDate.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(ProgramMedicinePrice);
break;
case "Edit":
OldPrice = OldPriceIfWasEdited;
break;
}
// Get day before next date in database as will be the range end
date.
DateTime RangeEndDate = GetRangeEndDate(ProgramMedicinePrice);
// 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 _AnimalMedicineList = From;
am;
dc.AnimalMedicines;
Where;
(ProgramMedicinePrice.ProgramId
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"CLS")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"REJ")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"PND")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"SHP")
& am.AnimalMedicineIsCharged))))) = true;
(ProgramMedicinePrice.MedicineId
& ((am.AnimalMedicineDateTime >=
ProgramMedicinePrice.ProgramMedicinePriceDate)
& ((am.AnimalMedicineDateTime <= RangeEndDate)
& am.Animal.LotPen.Lot.ProgramId))) = true;
am.MedicineId = true;
Group;
By;
LotPenId = am.Animal.LotPenId;
Into;
SumOfDosage = Sum(am.AnimalMedicineDosage);
switch (LotPenId) {
case SumOfDosage:
ToList();
// Loop through summed LotPenId and Dosage records and
create Charge entries.
for (int i = 0; (i
<= (_AnimalMedicineList.Count - 1)); i++) {
// For each sum of medicines used in a LotPen, enter
a DEBIT charge with the NEW amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars =
(Decimal.Parse(ProgramMedicinePrice.ProgramMedicinePriceDollars) *
_AnimalMedicineList[i]["SumOfDosage"]);
_Charge.LotPenId =
_AnimalMedicineList[i]["LotPenId"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
// For each sum of medicines used in a LotPen, enter
a CREDIT charge with the OLD amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars = (0
- (OldPrice *
_AnimalMedicineList[i]["SumOfDosage"]));
// Make amount NEGATIVE for the credit using OLD
price.
_Charge.LotPenId =
_AnimalMedicineList[i]["SumOfDosage"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
}
//
****************************************************************************************************************************************
// LotPenMedicine.
************************************************************************************************************************
IList _LotPenMedicineList = From;
lpm;
dc.LotPenMedicines;
Where;
(ProgramMedicinePrice.ProgramId
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"CLS")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"REJ")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"PND")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"SHP")
& lpm.LotPenMedicineIsCharged))))) = true;
(ProgramMedicinePrice.MedicineId
& ((lpm.LotPenMedicineDateTime >=
ProgramMedicinePrice.ProgramMedicinePriceDate)
& ((lpm.LotPenMedicineDateTime <=
RangeEndDate)
& lpm.LotPen.Lot.ProgramId))) = true;
lpm.MedicineId = true;
Group;
By;
LotPenId = lpm.LotPen.LotPenId;
Into;
SumOfDosage = Sum(lpm.LotPenMedicineDosage);
switch (LotPenId) {
case SumOfDosage:
ToList();
// Loop through summed LotPenId and Dosage
records and create Charge entries.
for (int i = 0; (i
<= (_LotPenMedicineList.Count - 1));
i++) {
// For each sum of medicines used in a
LotPen, enter a CREDIT charge with the NEW amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars =
(Decimal.Parse(ProgramMedicinePrice.ProgramMedicinePriceDollars) *
_LotPenMedicineList[i]["SumOfDosage"]);
_Charge.LotPenId =
_LotPenMedicineList[i]["LotPenId"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
// For each sum of medicines used in a
LotPen, enter a DEBIT charge with the OLD amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars = (0
- (OldPrice *
_LotPenMedicineList[i]["SumOfDosage"]));
// Make amount NEGATIVE for the debit using
OLD price.
_Charge.LotPenId =
_LotPenMedicineList[i]["SumOfDosage"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
}
//
****************************************************************************************************************************************
break;
}
break;
}
}
}



 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      2nd Jul 2008
Ronald S. Cook wrote:
> In trying to figure out how to make function
> MedicineClass.ApplyMedicinePriceChanges perform better, I ran Code
> Analysis and got the following:
>
> ******************************************************************************************
>
> Warning 1677 CA1506 : Microsoft.Maintainability :
> 'MedicineClass.ApplyMedicinePriceChanges(ProgramMedicinePrice, 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:
http://en.wikipedia.org/wiki/Couplin...ter_science%29

Arne
 
Reply With Quote
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      2nd Jul 2008
Ronald S. Cook wrote:
> In trying to figure out how to make function
> MedicineClass.ApplyMedicinePriceChanges perform better, I ran Code
> Analysis and got the following:
>
> ******************************************************************************************
> Warning 1677 CA1506 : Microsoft.Maintainability :
> 'MedicineClass.ApplyMedicinePriceChanges(ProgramMedicinePrice,
> 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\FRC.COW.Feedyard.DAL\Business
> Classes\MedicineClass.cs 514 FRC.COW.Feedyard.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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In VS2008 need to to change some statements that contain " class=" to " cssclass=" AAaron123 Microsoft VB .NET 2 4th Apr 2009 12:24 AM
Scope error: "public" member not found in "friend" class/sub =?Utf-8?B?dGltYm9iZA==?= Microsoft VB .NET 1 17th Dec 2005 05:46 PM
Tight coupling...or, "the theme of the day?" James Hokes Microsoft ADO .NET 1 25th Apr 2005 05:50 AM
"Unknown error" (or "0x80040154: Class not registered"). Please, h =?Utf-8?B?VmxhZA==?= Windows XP Help 0 8th Apr 2005 04:39 PM
Looking to impliment "First", "Second" & "Third" class of e-mails =?Utf-8?B?VENX?= Microsoft Outlook Discussion 0 12th Aug 2004 02:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.