-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathVisotorLesson.java
More file actions
43 lines (37 loc) · 827 Bytes
/
Copy pathVisotorLesson.java
File metadata and controls
43 lines (37 loc) · 827 Bytes
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
package patterns.behavioral;
public class VisotorLesson {
public static void main(String[] args) {
IAnimal animal = new Dog();
animal.doJob(new ConcreteVisitor());
new Cat().doJob(new ConcreteVisitor());
}
}
interface IAnimal {
void doJob(Visitor visitor);
}
class Dog implements IAnimal {
@Override
public void doJob(Visitor visitor) {
visitor.JobForDog();
}
}
class Cat implements IAnimal {
@Override
public void doJob(Visitor visitor) {
visitor.JobForCat();
}
}
interface Visitor {
void JobForDog();
void JobForCat();
}
class ConcreteVisitor implements Visitor {
@Override
public void JobForDog() {
System.out.println("dog");
}
@Override
public void JobForCat() {
System.out.println("cat");
}
}