Reputation: 1870
I am wondering if there is a way to have a dart class be public, but its contructor be library private. I have a JsonParsing library that will throw its own exception type, but it doesn't make sense for anyone outside of the library to construct this exception.
library json_parser;
import 'dart:convert';
class JsonParseException implements Exception {
final String cause;
JsonParseException(this.cause); // make this inaccessible in some way?
}
Upvotes: 1
Views: 161
Reputation: 277057
You can use a private named constructor:
class Foo {
Foo._();
}
Upvotes: 3