Skip to content

Commit f3a34c0

Browse files
committed
add more mdoc
1 parent 2c4f42d commit f3a34c0

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

_ko/tour/inner-classes.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ previous-page: lower-type-bounds
1212

1313
스칼라의 클래스는 다른 클래스를 멤버로 가질 수 있다. 자바와 같은 언어의 내부 클래스는 자신을 감싸고 있는 클래스의 멤버인 반면에, 스칼라에선 내부 클래스가 외부 객체의 경계 안에 있다. 이런 차이점을 분명히 하기 위해 그래프 데이터타입의 구현을 간단히 그려보자.
1414

15-
class Graph {
16-
class Node {
17-
var connectedNodes: List[Node] = Nil
18-
def connectTo(node: Node): Unit = {
19-
if (!connectedNodes.exists(node.equals)) {
20-
connectedNodes = node :: connectedNodes
21-
}
22-
}
23-
}
24-
var nodes: List[Node] = Nil
25-
def newNode: Node = {
26-
val res = new Node
27-
nodes = res :: nodes
28-
res
15+
```scala mdoc
16+
class Graph {
17+
class Node {
18+
var connectedNodes: List[Node] = Nil
19+
def connectTo(node: Node): Unit = {
20+
if (!connectedNodes.exists(node.equals)) {
21+
connectedNodes = node :: connectedNodes
2922
}
3023
}
24+
}
25+
var nodes: List[Node] = Nil
26+
def newNode: Node = {
27+
val res = new Node
28+
nodes = res :: nodes
29+
res
30+
}
31+
}
32+
```
3133

3234
이 프로그램에선 노드의 리스트로 그래프를 나타냈다. 노드는 내부 클래스 `Node`의 객체다. 각 노드는 리스트 `connectedNodes`에 저장되는 이웃의 목록을 갖고 있다. 이제 몇몇 노드를 선택하고 이에 연결된 노드를 추가하면서 점진적으로 그래프를 구축할 수 있다.
3335

0 commit comments

Comments
 (0)