-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathData.hx
99 lines (86 loc) · 2.67 KB
/
Data.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import contexts.DragDropMechanics.DragDropItem;
/**
* Used as a in-memory database for library items, cards and loans.
* The Main class is used to set up the data, hence the "allow" access control for Main.
*/
@:allow(Main) class Data
{
public static var libraryItems(default, null) : Array<LoanItem>;
public static var libraryCards(default, null) : Array<LibraryCard>;
public static var libraryLoans(default, null) : Array<LibraryLoan>;
}
///// Interfaces (artefacts that makes sense to a user in a context) /////
interface RfidItem
{
final rfid : String;
}
interface LoanItem extends RfidItem
{
final title : String;
final loanTimeDays : Int;
}
interface ScannedItem
{
var item(default, null) : LoanItem;
var returnDate(default, null) : Date;
}
///// Data classes (what the system is) /////
/**
* Some additional interfaces are used for the data classes:
*
* - @:publicFields metadata - making all class fields public
* - HaxeContracts: Design by Contract library
* - DataClass: A convenient way of creating and ensuring integrity of data objects
* - DragDropItem: A marker interface for objects that can be drag-dropped
*
*/
@:publicFields
class Book implements HaxeContracts implements DataClass
implements DragDropItem
implements LoanItem
{
@:validate(_.length > 0) final rfid : String;
@:validate(_.length > 0) final title : String;
@:validate(_ > 0) final loanTimeDays : Int;
}
@:publicFields
class Bluray implements HaxeContracts implements DataClass
implements DragDropItem
implements LoanItem
{
@:validate(_.length > 0) final rfid : String;
@:validate(_.length > 0) final title : String;
@:validate(_ > 0) final length : Int;
@:validate(_ > 0) final loanTimeDays : Int;
}
@:publicFields
class LibraryCard implements HaxeContracts implements DataClass
implements DragDropItem
implements RfidItem
{
@:validate(_.length > 0) final rfid : String;
@:validate(_.length > 0) final name : String;
@:validate(~/^\d{4}$/) final pin : String;
}
@:publicFields
class LibraryLoan implements HaxeContracts implements DataClass
{
@:validate(_.length > 0) final loanItemRfid : String;
@:validate(_.length > 0) final borrowerRfid : String;
final created : Date;
final returnDate : Date;
}
class ReceiptItem implements HaxeContracts
implements ScannedItem
{
public var item(default, null) : LoanItem;
public var returnDate(default, null) : Date;
public function new(item, returnDate) {
this.item = item;
this.returnDate = returnDate;
}
@invariants function invariants() {
Contract.invariant(this.item != null);
Contract.invariant(this.returnDate != null);
}
}