Skip to content

Commit 6f05d3f

Browse files
committed
[Samples] Improve Composition vs Inheritance sample
1 parent 2ad07db commit 6f05d3f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

LessonsSamples/LessonsSamples/Lesson7/CohesionCoupling/PageXml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ namespace LessonsSamples.Lesson7.CohesionCoupling
55
public class PageXml
66
{
77
public CustomerXml Customer { get; set; }
8+
9+
//.... other properties that describe the XML format of a page w/ customer data
810
}
911

1012
public class CustomerXml
1113
{
1214
public string Name { get; set; }
1315
public List<AddressXml> Addresses { get; set; }
16+
17+
//.... other properties that describe the XML format of a customer
1418
}
1519

1620
public class AddressXml

LessonsSamples/LessonsSamples/Lesson7/InheritanceComposition/Account.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ public decimal MonthlyInterest()
2929
return amount*interestRate/100;
3030
}
3131

32-
public virtual void MonthlyRenewal()
32+
public virtual void MonthlyRenewal(Month currentMonth)
3333
{
3434
decimal interest = MonthlyInterest();
35-
decimal taxes = CalculateTaxesForMoth(CurrentMonth);
35+
decimal taxes = CalculateTaxesForMoth(currentMonth);
3636

3737
amount = amount + interest - taxes;
3838
}
39-
40-
public Month CurrentMonth { get; set; }
4139
}
4240

4341
class SavingsAccount : Account
@@ -96,10 +94,10 @@ public AutoLoanAccount(decimal interestRate) : base(interestRate)
9694
{
9795
}
9896

99-
public override void MonthlyRenewal()
97+
public override void MonthlyRenewal(Month currentMonth)
10098
{
10199
decimal interest = MonthlyInterest();
102-
decimal taxes = CalculateTaxesForMoth(CurrentMonth);
100+
decimal taxes = CalculateTaxesForMoth(currentMonth);
103101

104102
Amount = Amount - interest - taxes;
105103
}

0 commit comments

Comments
 (0)