44 lines
1010 B
Dart
44 lines
1010 B
Dart
|
import 'package:mock/person.dart';
|
||
|
import 'package:mock/business.dart';
|
||
|
import 'package:mock/person_data_access_map.dart';
|
||
|
import 'package:mock/person_data_access_sqlite.dart';
|
||
|
|
||
|
/*
|
||
|
@startuml
|
||
|
class Business {
|
||
|
- PersonDataAccessMap backend
|
||
|
}
|
||
|
PersonDataAccessMap <-left- Business : uses
|
||
|
|
||
|
class PersonDataAccessMap {
|
||
|
- Map<int, Person> map
|
||
|
+ store(Person p): void
|
||
|
+ retrieve(int id): Person
|
||
|
+ retrieveAll(): List<Person>
|
||
|
}
|
||
|
|
||
|
class PersonDataAccessSqlite implements PersonDataAccessMap {
|
||
|
- Sqlite db
|
||
|
+ store(Person p): void
|
||
|
+ retrieve(int id): Person
|
||
|
+ retrieveAll(): List<Person>
|
||
|
}
|
||
|
@enduml
|
||
|
*/
|
||
|
void main() {
|
||
|
PersonDataAccessMap backend = PersonDataAccessSqlite("sqlite3.db");
|
||
|
Business b = Business(backend);
|
||
|
|
||
|
List<Person> persons = b.getAllPersons();
|
||
|
int personCount = persons.length;
|
||
|
|
||
|
print("We know $personCount persons");
|
||
|
|
||
|
int nextPersonId = ++personCount;
|
||
|
b.addPerson(Person(nextPersonId, "A New Person"));
|
||
|
|
||
|
print("Now we know ${b.getAllPersons().length} persons");
|
||
|
|
||
|
backend.close();
|
||
|
}
|