Skip to content

Commit

Permalink
Update concrete class to implement the Element interface
Browse files Browse the repository at this point in the history
Then in demo.ts no need to cast from Concrete Element to Element
  • Loading branch information
Vo Tuan Trung committed Dec 28, 2016
1 parent 01ee72f commit 909af0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions visitor/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace VisitorPattern {
export function show() : void {
var objs: VisitorPattern.Objs = new VisitorPattern.Objs();

objs.attach(<VisitorPattern.Element> new VisitorPattern.ConcreteElement1());
objs.attach(<VisitorPattern.Element> new VisitorPattern.ConcreteElement2());
objs.attach(new VisitorPattern.ConcreteElement1());
objs.attach(new VisitorPattern.ConcreteElement2());

var v1: VisitorPattern.ConcreteVisitor1 = new VisitorPattern.ConcreteVisitor1(),
v2: VisitorPattern.ConcreteVisitor2 = new VisitorPattern.ConcreteVisitor2();
Expand Down
4 changes: 2 additions & 2 deletions visitor/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ namespace VisitorPattern {
operate(visitor: Visitor): void;
}

export class ConcreteElement1 {
export class ConcreteElement1 implements Element {
public operate(visitor: Visitor): void {
console.log("`operate` of ConcreteElement1 is being called!");
visitor.visitConcreteElement1(this);
}
}

export class ConcreteElement2 {
export class ConcreteElement2 implements Element {
public operate(visitor: Visitor): void {
console.log("`operate` of ConcreteElement2 is being called!");
visitor.visitConcreteElement2(this);
Expand Down

0 comments on commit 909af0a

Please sign in to comment.