学习某种设计模式,架构?

Service

package com.ylz.consumer.web.routeable;



public interface Service {
	
	/**
	 * 订购
	 * @param request	订购请求参数
	 * @return
	 */
	public String order(String request);
}



Routeable

package com.ylz.consumer.web.routeable;

import java.util.HashMap;
import java.util.Map;

public class Routeable implements Service{
	
	static Map<String ,Service > serviceMap = new HashMap<String, Service>();

	static{
		Service aService = new AService();
		Service bService = new BService();
		Service cService = new CService();
		serviceMap.put("aService", aService);
		serviceMap.put("bService", bService);
		serviceMap.put("cService", cService);
	}
	
	@Override
	public String order(String request) {
		// TODO Auto-generated method stub
		Service service = serviceMap.get(request);
		service.order(request);
		return null;
	}
	
	
	
	public static void main(String[] args) {
		Routeable r = new Routeable();
		String service = "";
		// TODO Auto-generated method stub
		System.out.println("---------------select AService---------------");
		service = "aService";
		r.order(service);
		System.out.println("---------------select AService---------------");
		System.out.println("---------------select BService---------------");
		service = "bService";
		r.order(service);
		System.out.println("---------------select BService---------------");
		System.out.println("---------------select CService---------------");
		service = "cService";
		r.order(service);
		System.out.println("---------------select CService---------------");
	}
}

AbstracService

package com.ylz.consumer.web.routeable;






abstract public class AbstracService implements Service{
	
	@Override
	public String order(String request) {
		// TODO Auto-generated method stub
		System.out.println("all Services need to go in this");
		process(request);
		return null;
	}
	
	//所有继承的子类 必须实现 抽象方法
	abstract public void process(String request);
}

AService

package com.ylz.consumer.web.routeable;






public class AService extends AbstracService{

	//与其他继承  AbstracService 的  自定义的方法
	@Override
	public void process(String request) {
		// TODO Auto-generated method stub
		System.out.println("我是:"+request);
	}
	
}

BService

package com.ylz.consumer.web.routeable;






public class BService extends AbstracService{

	//与其他继承  AbstracService 的  自定义的方法
	@Override
	public void process(String request) {
		// TODO Auto-generated method stub
		System.out.println("我是:"+request);
	}
	
}

CService

package com.ylz.consumer.web.routeable;






public class CService extends AbstracService{

	//与其他继承  AbstracService 的  自定义的方法
	@Override
	public void process(String request) {
		// TODO Auto-generated method stub
		System.out.println("我是:"+request);
	}

}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值