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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
classDiagram
class Entity {
<<abstract>>
+int Id
+string Type
+(int x, int y) Location
+(int x, int y) Direction
+bool IsAlive
+IMovementStrategy MovementStrategy
+IFeedingStrategy FeedingStrategy
+List~string~ PreyTypes
+Entity Prey
-List~Entity~ _observers
+Attach(observer: Entity)
+Detach(observer: Entity)
+Notify()
+Update(subject: Entity)
+Move()
+Feed()
+CanEat(targetType: string) bool
+CalculateDirectionToTarget(target: (int, int)) (int, int)
+DistanceTo(target: (int, int)) double
}
class Morg {
+Morg(id, location, direction)
}
class Simulator~T~ {
<<abstract>>
#List~T~ _entities
#const double FEEDING_DISTANCE
+AddEntity(entity: T)
+GetAllEntities() IEnumerable~T~
+CreateIterator() IEntityIterator~T~
+Run(runTime: int)
#ProcessTimeStep()
#FindPreyIfNeeded(entity: T)
#CheckAndFeed(entity: T)
#FindNearestPrey(predator: T) Entity*
}
class Dish {
+AddMorg(morg: Morg)
+GetAllMorgs() List~Morg~
#FindNearestPrey(predator: Morg) Entity*
}
class IMovementStrategy {
<<interface>>
+Move(entity: Entity, newLocation: (int, int))
}
class MovementStrategyPaddles {
+Move(entity: Entity, newLocation: (int, int))
}
class MovementStrategyOozes {
+Move(entity: Entity, newLocation: (int, int))
}
class IFeedingStrategy {
<<interface>>
+Feed(predator: Entity, prey: Entity)
}
class FeedingStrategyAbsorbs {
+Feed(predator: Entity, prey: Entity)
}
class FeedingStrategyEnvelops {
+Feed(predator: Entity, prey: Entity)
}
class Reader {
<<abstract>>
+ReadLine() string*
+EndOfStream bool
+Close()
}
class FileReader {
-StreamReader _streamReader
+ReadLine() string*
}
class ReaderDecorator {
<<abstract>>
#Reader _reader
+ReadLine() string*
}
class CSVReader {
+ReadLine() string*
+ReadCSVLine() string[]*
}
class EntityReader~T~ {
<<abstract>>
#IEntityFactory~T~ _factory
+ReadEntity(id: int) T*
}
class MorgReader {
+ReadEntity(id: int) Morg*
}
class IEntityFactory~T~ {
<<interface>>
+CreateEntity(id, type, x, y, movement, feeding) T
+CreateMovementStrategy(movementType) IMovementStrategy
+CreateFeedingStrategy(behavior) IFeedingStrategy
}
class MorgFactory {
+CreateEntity(...) Morg
+CreateMovementStrategy(...) IMovementStrategy
+CreateFeedingStrategy(...) IFeedingStrategy
-ParsePreyTypes(feedingParts) List~string~
}
class IEntityIterator~T~ {
<<interface>>
+HasNext() bool
+Next() T*
+Reset()
}
class EntityIterator~T~ {
-List~T~ _entities
-int _currentIndex
+HasNext() bool
+Next() T*
+Reset()
}
class Program {
+Main()
}
Entity <|-- Morg
Simulator~T~ <|-- Dish
Entity --> IMovementStrategy : uses
Entity --> IFeedingStrategy : uses
Entity --> Entity : Observer Pattern
IMovementStrategy <|.. MovementStrategyPaddles
IMovementStrategy <|.. MovementStrategyOozes
IFeedingStrategy <|.. FeedingStrategyAbsorbs
IFeedingStrategy <|.. FeedingStrategyEnvelops
Reader <|-- FileReader
Reader <|-- ReaderDecorator
ReaderDecorator <|-- CSVReader
ReaderDecorator <|-- EntityReader~T~
EntityReader~T~ <|-- MorgReader
EntityReader~T~ --> IEntityFactory~T~ : uses
IEntityFactory~T~ <|.. MorgFactory
MorgFactory --> Morg : creates
MorgFactory --> IMovementStrategy : creates
MorgFactory --> IFeedingStrategy : creates
Simulator~T~ --> IEntityIterator~T~
IEntityIterator~T~ <|.. EntityIterator~T~
Dish --> Morg
Program --> Dish
Program --> FileReader
Program --> CSVReader
Program --> MorgReader
Program --> MorgFactory
|