I’m writing a library with structures of varying precision level, such as a point with integer coordinates and a point with floating-point coordinates. .NET uses Point for its integral structure, and PointF for the floating-point variant, but I recently stumbled across Java’s equivalent, which uses Point and a nested Point.Double.
I like the idea of defining types like this:
struct Point {
// integral implementation
public struct Double {
// double floating-point implementation
}
public struct Long {
// 64-bit implementation
}
// etc..
}
What I don’t like is redefining “Double” and “Long” inside the parent type. Has anyone used this pattern and found any more problems that arise from it? Or should I stick with Point, PointD, & PointL?
I despise this idea. I think of nested classes as implementation details of the containing class, and a point with
doublefields is not an implementation detail of a point withintfields. Nested classes are used for encapsulating implementation details that do not make sense outside of their containing class. Here, that is just not the case. Don’t do this.Also, I don’t see why you just wouldn’t go with the naming convention: