forked from idg10/prog-cs-8-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassHierarchy.cs
36 lines (31 loc) · 970 Bytes
/
ClassHierarchy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
namespace Generics
{
public class Shape
{
public Rect BoundingBox { get; set; }
}
public class RoundedRectangle : Shape
{
public double CornerRadius { get; set; }
}
public class BoxAreaComparer : IComparer<Shape>
{
public int Compare(Shape x, Shape y)
{
double xArea = x.BoundingBox.Width * x.BoundingBox.Height;
double yArea = y.BoundingBox.Width * y.BoundingBox.Height;
return Math.Sign(xArea - yArea);
}
}
public class CornerSharpnessComparer : IComparer<RoundedRectangle>
{
public int Compare(RoundedRectangle x, RoundedRectangle y)
{
// Smaller corners are sharper, so smaller radius is "greater" for
// the purpose of this comparison, hence the backward subtraction.
return Math.Sign(y.CornerRadius - x.CornerRadius);
}
}
}