By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,418 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,418 IT Pros & Developers. It's quick & easy.

What is "class coupling", please?

P: n/a

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(ProgramMe dicinePrice, 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\B usiness
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.Da te <
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.ProgramMedicin ePriceDollars) *
_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.ProgramMedicin ePriceDollars) *
_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;
}
}
}

Jul 1 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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(ProgramMe dicinePrice, 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
Jul 1 '08 #2

P: n/a
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(ProgramMe dicinePrice,
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\B usiness
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

Jul 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.