Skip to content

Commit 909af0a

Browse files
author
Vo Tuan Trung
committed
Update concrete class to implement the Element interface
Then in demo.ts no need to cast from Concrete Element to Element
1 parent 01ee72f commit 909af0a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

visitor/demo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace VisitorPattern {
55
export function show() : void {
66
var objs: VisitorPattern.Objs = new VisitorPattern.Objs();
77

8-
objs.attach(<VisitorPattern.Element> new VisitorPattern.ConcreteElement1());
9-
objs.attach(<VisitorPattern.Element> new VisitorPattern.ConcreteElement2());
8+
objs.attach(new VisitorPattern.ConcreteElement1());
9+
objs.attach(new VisitorPattern.ConcreteElement2());
1010

1111
var v1: VisitorPattern.ConcreteVisitor1 = new VisitorPattern.ConcreteVisitor1(),
1212
v2: VisitorPattern.ConcreteVisitor2 = new VisitorPattern.ConcreteVisitor2();

visitor/visitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ namespace VisitorPattern {
2929
operate(visitor: Visitor): void;
3030
}
3131

32-
export class ConcreteElement1 {
32+
export class ConcreteElement1 implements Element {
3333
public operate(visitor: Visitor): void {
3434
console.log("`operate` of ConcreteElement1 is being called!");
3535
visitor.visitConcreteElement1(this);
3636
}
3737
}
3838

39-
export class ConcreteElement2 {
39+
export class ConcreteElement2 implements Element {
4040
public operate(visitor: Visitor): void {
4141
console.log("`operate` of ConcreteElement2 is being called!");
4242
visitor.visitConcreteElement2(this);

0 commit comments

Comments
 (0)