|
| 1 | +package org.javacore.base.inter; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | + |
| 5 | +/* |
| 6 | + * Copyright [2015] [Jeff Lee] |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +/** |
| 22 | + * @author Jeff Lee |
| 23 | + * @since 2015-12-1 13:04:30 |
| 24 | + * 不使用接口的接口案例 |
| 25 | + */ |
| 26 | +class Processor { |
| 27 | + public String name(){ |
| 28 | + return getClass().getSimpleName(); |
| 29 | + } |
| 30 | + |
| 31 | + Object process(Object input){return input;} |
| 32 | +} |
| 33 | + |
| 34 | +class Upcase extends Processor { |
| 35 | + @Override |
| 36 | + Object process(Object input) { |
| 37 | + return ((String)input).toUpperCase(); |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +class Splitcase extends Processor { |
| 42 | + @Override |
| 43 | + Object process(Object input) { |
| 44 | + return Arrays.toString(((String) input).split(" ")); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +public class ApplyClass { |
| 49 | + public static void process(Processor p , Object input){ |
| 50 | + System.out.println("调用对象名:" + p.name()); |
| 51 | + System.out.println(p.process(input)); |
| 52 | + } |
| 53 | + |
| 54 | + public static String s = "BYSocket's Blog is www.bysocket.com"; |
| 55 | + public static void main(String[] args) { |
| 56 | + process(new Upcase(),s); |
| 57 | + process(new Splitcase(),s); |
| 58 | + } |
| 59 | +} |
0 commit comments