Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define more specific return type on newWith and newFrom methods of Point sub classes #41

Closed
navispatial opened this issue Nov 27, 2021 · 1 comment
Labels
🌐 geocore Related to the code package "geocore" refactoring

Comments

@navispatial
Copy link
Member

The abstract Point class following factory methods to create new point instances of the same sub type methods are called on.

  Point newWith({num x = 0.0, num y = 0.0, num? z, num? m});
  Point newFrom(Iterable<num> coords, {int? offset, int? length});

Sub classes like Point2 implement these methods like:

  @override
  Point newWith({num x = 0.0, num y = 0.0, num? z, num? m}) =>
      Point2(x: x, y: y);

  @override
  Point newFrom(Iterable<num> coords, {int? offset, int? length}) {
    CoordinateFactory.checkCoords(2, coords, offset: offset, length: length);
    return Point2.from(coords, offset: offset);
  }

This should work fine.

However if you are using a specific Point sub type, like Point2, then it might be useful to define more specific return type.

That is, for Point2 the implementation would change to following:

  @override
  Point2 newWith({num x = 0.0, num y = 0.0, num? z, num? m}) =>
      Point2(x: x, y: y);

  @override
  Point2 newFrom(Iterable<num> coords, {int? offset, int? length}) {
    CoordinateFactory.checkCoords(2, coords, offset: offset, length: length);
    return Point2.from(coords, offset: offset);
  }
@navispatial navispatial added refactoring 🌐 geocore Related to the code package "geocore" labels Nov 28, 2021
@navispatial
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌐 geocore Related to the code package "geocore" refactoring
Projects
None yet
Development

No branches or pull requests

1 participant