類別圖:歌曲排行(迭代器模式)

Example: 歌曲排行


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
@startuml Example-Top-Song-Iterator-Pattern

interface Traversable
{
}

interface Iterator
{
+ current(): mixed
+ key(): scalar
+ next()
+ rewind()
+ valid(): bool
}

interface IteratorAggregate
{
+ getIterator(): Traversable
}

Traversable <|-- Iterator
Traversable <|-- IteratorAggregate

class Song
{
# name: string
# singer: string
# releaseDate: DateTime

+ __construct(array data)

+ getName(): string
+ getSinger(): string
+ getReleaseDate(): DateTime
}

class SongCollection
{
# dataOfSongs: array
# items: Song[]

+ __construct(array dataOfSongs)

- generateSongs(array dataOfSongs): Song[]
+ getItems(): Song[]
+ reverse(): static
}

IteratorAggregate <|.. SongCollection
Song -o SongCollection

class SongIterator
{
# collection: SongCollection
# position: int

+ __construct(SongCollection songCollection)
}

Iterator <|.. SongIterator
SongCollection <- SongIterator

class Program
{
# songCollection: SongCollection

+ __construct(array song)
+ list(): array
+ listReverse(): array
}

SongCollection <-- Program

@enduml

ʕ •ᴥ•ʔ:若不熟悉 UML 類別圖,可參考UML類別圖說明

Share