namespace Playful {
void nickname();
}
namespace Person {
void name();
}
namespace Locatable {
void geolocation();
}
class Alice implements Locatable, Playful, Person, {
// ...
}
function show_on_map(Locatable locatable) {
// ...
}
function start_game(Playful playful) {
// ...
}
function bill(Person person) {
// ...
}How would one translate the following pseudocode to Dart in it's new no-namespace approach?
class Playful {
void nickname();
}
class Person {
void name();
}
class Locatable {
void geolocation();
}
class Alice implements Locatable, Playful, Person, {
// ...
}
function show_on_map(Locatable locatable) {
// ...
}
function start_game(Playful playful) {
// ...
}
function bill(Person person) {
// ...
}
Hello,How would one translate the following pseudocode to Dart in it's new no-namespace approach?
Since namespaces were brought up I've been wondering why Dart doesn't allow you to declare one?
Its useful within a library to group a bunch of functions together under one name, and to me it feels wrong when I have to create a class that will never be instantiated which contains nothing but static methods.
The Futures class is a good candidate for being a namespace rather than a class. It just has a static method and there's no reason to create a Futures class ever.
new Future.waitAll(Collection<Future> futures);
Yea I know you can namespace a library but having to go that route for a handful of functions seems overkill. Then the clients have to import every sub-library within your library,
and the developer has to make sure it conforms with pub.
At that point its less work on everyone to just use a class with nothing but static members even though free functions would be the better design.Its not a deal breaker for me to not have it. I was just curious if there was some reason the Dart team was against being able to explicitly declare a namespace around some functions.
Yea I know you can namespace a library but having to go that route for a handful of functions seems overkill. Then the clients have to import every sub-library within your library,
Yea I know you can namespace a library but having to go that route for a handful of functions seems overkill. Then the clients have to import every sub-library within your library,> True. :(
Really? I'm using this approach and it seems to work for me. The top-level library just needs to 'export' the sub-libraries. Then your user can just import the top-level library if he wants 'it all', or pick and choose. I kind of like it a lot :)
controllers/Foo.dart
models/Foo.dartlibrary foo_controller;library foo_model;library controllers;
class Foo {}
class Bar {}library models;
class Foo {}
class Bar {}library myapp_controllers;
class Foo {}
class Bar {}library quxapp_controllers;
class Foo {}
class Bar {}library myapp;
class FooController {} // Defined in controllers/FooController.dart
class FooModel {} // Defined in models/FooModel.dartI think the simplest is to have an app as a single library, and then just prefix/postfix accordingly:library myapp;
class FooController {} // Defined in controllers/FooController.dart
class FooModel {} // Defined in models/FooModel.dart
--