-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
39 lines (31 loc) · 1.31 KB
/
Copy pathMain.java
File metadata and controls
39 lines (31 loc) · 1.31 KB
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
import generator.RandomObjectGenerator;
import model.MyClass;
import model.MyRecord;
import proxy.CacheProxy;
import annotations.Cache;
import proxy.FibCalculator;
public class Main {
public static void main(String[] args) {
// генератор объектов
RandomObjectGenerator rog = new RandomObjectGenerator();
var myClass = rog.nextObject(MyClass.class, "create"); //через фабрику
System.out.println("MyClass (factory): " + myClass);
var myRecord = rog.nextObject(MyRecord.class); //через конструктор
System.out.println("MyRecord (random): " + myRecord);
// обычная реализация
FibCalculator original = new FibCalculator() {
@Override
@Cache(persist = true)
public long fib(int number) {
if (number <= 1) return number;
return fib(number - 1) + fib(number - 2);
}
};
// кэш-прокси
FibCalculator proxy = CacheProxy.create(original, FibCalculator.class);
// вызовы с кэшированием
System.out.println("fib(5): " + proxy.fib(5));
System.out.println("fib(6): " + proxy.fib(6));
System.out.println("fib(5) again (from cache): " + proxy.fib(5));
}
}