473,583 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;
}
}
}

Jul 1 '08 #1
2 11917
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:
http://en.wikipedia.org/wiki/Couplin...ter_science%29

Arne
Jul 1 '08 #2
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

Jul 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3779
by: Dominik Kaspar | last post by:
i'm used to java and its strict way of defining variables. so how is it possible to reach something like a class variable in python? with the following code i didn't have much succes... class Server(threading.Thread): running = 0 (??) def run(self): running = 1 while running:
4
2483
by: Jian H. Li | last post by:
Hello, What's the essential differences between the two ways of "class::member" & "object.member"(or object_pointer->member)? class C{ public: void f() {} int i; };
3
1845
by: Alexander Farber | last post by:
Hi, does anyone have an idea, why do I get the following error (I have to use g++296 on RedHat Linux as compiler): In file included from r_dir.cpp:9: r_obey.h:262: declaration of `const AreaSet &CObeyFile::AreaSet () const' r_areaset.h:197: changes meaning of `AreaSet' from `class AreaSet'
9
1992
by: MLH | last post by:
I need a fundamental explanation of Class Modules - something suitable for newbies. Access 2.0 didn't seem to focus on them very much. Now that I'm using Access 97, it seems they're everywhere. thx N advance.
2
1171
by: '[] WiRaN | last post by:
I all, I need a classroom equivalent the "Class List" of c++, necessary to recoup given of some hands tanks, Bruno
45
3421
by: Gregory Petrosyan | last post by:
1) From 2.4.2 documentation: There are two new valid (semantic) forms for the raise statement: raise Class, instance raise instance 2) In python: >>> raise NameError Traceback (most recent call last): File "<stdin>", line 1, in ? NameError
38
2027
by: looping | last post by:
For Python developers around. >From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass nice but why this syntax return old-style class, same as "class C:", and not the new style "class C(object):" ?
0
1621
by: bjpandapark | last post by:
Hi, I am working on my homework...and I have to do create a class where it can calculate the area of the rectangle while under these conditions.. 1. limit the width and length ...under 20 2. use set_length, get_length, set_width, and so on..and have the user input the length and width value 3. after the calculation is done, I have to...
3
2273
by: nadeem_far | last post by:
Hello All, I have a couple of questions and I am not able to find them any where on internet. 1. We are using a third party class library which exposes a class with the name of "class". Now how can i create an object of this "class" class as class is a reserve word in C#.
0
7811
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8314
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7922
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8185
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6571
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3811
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.