/
ExternalClass.java
44 lines (28 loc) · 1.06 KB
/
ExternalClass.java
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
package com.behavioural.visitor;
public class ExternalClass {
/**
* Simpler version of Visitor.
*
* from https://github.com/chirey/designPatternsThoughtsCode
*
*
* @param args
*/
public static void main(String args[]){
//Step 3.a - create the visitor
VisitorInterface visitor = new AVisitorClass();
//Step 3b. We create an instance of the ExistingClass.
AExistingClass aExistingObject = new AExistingClass();
aExistingObject.setVariableA("initial value");
//General method call
aExistingObject.methodA();
//Step 3c - Call the method
aExistingObject.accept(visitor);
//Generalizing
/**
* I can add any function to classes AExistingClass BExistingClass, though it was not there initially.
*
* 1. when ever I call ca.accept( with the new function in here) the function gets called.
*/
}
}