1
1
package com.kotlin.leran
2
2
3
- import com.kotlin.leran.algorithm.Test
4
- import com.kotlin.leran.basis.*
5
- import com.kotlin.leran.cls.TypealiasDemo
6
- import com.kotlin.leran.cls.classDemo.*
7
- import com.kotlin.leran.coroutines.Basis
8
- import com.kotlin.leran.coroutines.CancelCoroutineDemo
9
3
import com.kotlin.leran.design.adapter.ClassAdapter
10
4
import com.kotlin.leran.design.adapter.DefaultAdapter
11
5
import com.kotlin.leran.design.adapter.ObjectAdapter
12
- import com.kotlin.leran.function.BasisFunctionDemo
13
- import com.kotlin.leran.function.InfixFunDemo
14
- import com.kotlin.leran.function.SeniorFunctionDemo
15
- import com.kotlin.leran.function.lambda.LambdaDemo
16
- import com.kotlin.leran.other.CollectionDemo
17
- import com.kotlin.leran.other.OperaCollectionDemo
18
- import kotlin.contracts.contract
6
+ import com.kotlin.leran.design.proxy.dynamic.cglib.Car
7
+ import com.kotlin.leran.design.proxy.dynamic.cglib.TestCglibFactory
8
+ import com.kotlin.leran.design.proxy.dynamic.jdk.*
9
+ import com.kotlin.leran.design.proxy.statics.demo1.Driver
10
+ import com.kotlin.leran.design.proxy.statics.demo1.FirstDriver
11
+ import com.kotlin.leran.design.proxy.statics.demo1.MoneyProxy
12
+ import com.kotlin.leran.design.proxy.statics.demo2.PlaneProxy
13
+ import com.kotlin.leran.design.proxy.statics.demo2.RailwayProxy
14
+ import com.kotlin.leran.design.proxy.statics.demo2.User
15
+ import java.lang.reflect.Proxy
19
16
20
17
/* *
21
18
* Desc : 程序入口类
@@ -24,7 +21,7 @@ import kotlin.contracts.contract
24
21
25
22
* Version : v-1.0.1
26
23
*/
27
- suspend fun main (args : Array <String >) {
24
+ fun main (args : Array <String >) {
28
25
29
26
// 测试 HelloWorld
30
27
// HelloWorld().test()
@@ -83,8 +80,6 @@ suspend fun main(args: Array<String>) {
83
80
// 测试 类型别名
84
81
// TypealiasDemo().test()
85
82
86
-
87
-
88
83
// 测试 Lambda语法
89
84
// LambdaDemo().test()
90
85
@@ -93,7 +88,6 @@ suspend fun main(args: Array<String>) {
93
88
// infixDemo testInFix ("测试中缀函数")
94
89
// infixDemo.test()
95
90
96
-
97
91
// 测试高阶函数
98
92
// SeniorFunctionDemo().test()
99
93
@@ -104,20 +98,84 @@ suspend fun main(args: Array<String>) {
104
98
// OperaCollectionDemo().test()
105
99
106
100
// 测试协程
107
- // Basis().test()
108
- // CancelCoroutineDemo().test()
101
+ // testCoroutine()
109
102
103
+ // 测试 适配器模式
104
+ // testAdapter()
110
105
106
+ // 测试静态代理
107
+ // testStaticsProxy()
111
108
112
- // 测试 适配器模式
113
- // ClassAdapter().test()
114
- // ObjectAdapter().test()
115
- // DefaultAdapter().test()
116
-
117
- val test = Test ()
118
- // test.test2(10000)
119
- // test.test3(10000)
120
- test.test4(10 )
121
- test.test5(10 )
109
+ // 测试动态代理
110
+ // testDynamicProxy()
111
+ }
112
+
113
+ /* *
114
+ * 测试协程
115
+ */
116
+ private fun testCoroutine (){
117
+
118
+ }
119
+
120
+ /* *
121
+ * 测试算法
122
+ */
123
+ private fun testAlgorithm (){
124
+
125
+ }
126
+
127
+ /* *
128
+ * 测试适配器模式
129
+ */
130
+ private fun testAdapter (){
131
+ ClassAdapter ().test()
132
+ ObjectAdapter ().test()
133
+ DefaultAdapter ().test()
134
+ }
135
+
136
+ /* *
137
+ * 测试静态代理
138
+ */
139
+ private fun testStaticsProxy (){
140
+ val user = User ()
141
+ val planeProxy = PlaneProxy (user)
142
+ planeProxy.buyTicket(" 深圳-重庆" , 783.56 )
143
+
144
+ val railwayProxy = RailwayProxy (user)
145
+ railwayProxy.buyTicket(" 广州南-重庆西" , 428.23 )
146
+
147
+ val driver = Driver ()
148
+ val driverProxy2 = MoneyProxy (driver)
149
+ driverProxy2.giveMoney(5 ,13 )
150
+
151
+ val firstDriver = FirstDriver ()
152
+ firstDriver.giveMoney(7 ,12 )
153
+ }
154
+
155
+ /* *
156
+ * 测试动态代理
157
+ */
158
+ private fun testDynamicProxy (){
159
+ val railway = Railway ()
160
+ var handler = ProxyHandler (railway)
161
+ val railwayProxy = Proxy .newProxyInstance(railway.javaClass.classLoader,
162
+ railway.javaClass.interfaces, handler) as IDynamicTicket
163
+ railwayProxy.buyTicket(" 广州南-重庆西" , 428.34 )
164
+
165
+ val plane = Plane ()
166
+ handler = ProxyHandler (plane)
167
+ val planeProxy = Proxy .newProxyInstance(plane.javaClass.classLoader,
168
+ plane.javaClass.interfaces, handler) as IDynamicTicket
169
+ planeProxy.buyTicket(" 深圳-重庆" , 1028.34 )
170
+
171
+ val boat = Boat ()
172
+ handler = ProxyHandler (boat)
173
+ val boatProxy = Proxy .newProxyInstance(boat.javaClass.classLoader,
174
+ boat.javaClass.interfaces, handler) as IDynamicTicket
175
+ boatProxy.buyTicket(" 深圳-香港" , 167.34 )
176
+
177
+ val car = Car ()
178
+ val carProxy = TestCglibFactory (car).creator()
179
+ carProxy.buyCarTicket(" 深圳-广州" , 137.5 )
122
180
123
181
}
0 commit comments