大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
nginx_module_t
定义模块,结构体里有若干函数指针和扩展字段,然后桥接实现了丰富多彩的 core、conf、event、stream、http 等功能模块,搭建起整个 Nginx 框架HandsetSoft
实现类:public abstract class HandsetSoft {
public abstract void run();
}
HandsetSoft
具体实现类:public class HandsetGame extends HandsetSoft {
@Override
public void run() {
System.out.println("运行手机游戏");
}
}
public class HandsetAddressList extends HandsetSoft {
@Override
public void run() {
System.out.println("运行手机通讯录");
}
}
HandsetBrand
抽象类:public abstract class HandsetBrand {
protected HandsetSoft soft;
public void SetHandsetSoft(HandsetSoft soft) {
this.soft = soft;
}
public abstract void run();
}
HandsetBrand
扩展抽象类:public class HandsetBrandM extends HandsetBrand {
@Override
public void run() {
soft.run();
}
}
public class HandsetBrandN extends HandsetBrand {
@Override
public void run() {
soft.run();
}
}
public class Main {
public static void main(String[] args) {
HandsetBrand ab;
ab = new HandsetBrandN();
ab.SetHandsetSoft(new HandsetGame());
ab.run();
ab.SetHandsetSoft(new HandsetAddressList());
ab.run();
ab = new HandsetBrandM();
ab.SetHandsetSoft(new HandsetGame());
ab.run();
ab.SetHandsetSoft(new HandsetAddressList());
ab.run();
}
}
Request
类:public class Request {
private String requestType;
private String requestContent;
private int number;
public String getRequestType() {
return requestType;
}
public void setRequestType(String requestType) {
this.requestType = requestType;
}
public String getRequestContent() {
return requestContent;
}
public void setRequestContent(String requestContent) {
this.requestContent = requestContent;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
Manager
类:public abstract class Manager {
protected String name;
protected Manager superior;
protected Manager(String name) {
this.name = name;
}
public void SetSuperior(Manager superior) {
this.superior = superior;
}
public abstract void requestApplications(Request request);
}
ConcreteManager
类:public class GeneralManager extends Manager {
protected GeneralManager(String name) {
super(name);
}
@Override
public void requestApplications(Request request) {
if(request.getRequestType() == "请假"){
System.out.println(name + ":" + request.getRequestContent() + " 数量" + request.getNumber() + " 被批准" );
}else if(request.getRequestType() == "加薪" && request.getNumber()<= 500) {
System.out.println(name + ":" + request.getRequestContent() + " 数量" + request.getNumber() + " 被批准" );
}else {
System.out.println(name + ":" + request.getRequestContent() + " 数量" + request.getNumber() + " 再说吧" );
}
}
}
public class MajorDemo extends Manager {
protected MajorDemo(String name) {
super(name);
}
@Override
public void requestApplications(Request request) {
if(request.getRequestType() == "请假" && request.getNumber()<= 5) {
System.out.println(name + ":" + request.getRequestContent() + " 数量" + request.getNumber() + " 被批准" );
}else {
if(superior != null) {
superior.requestApplications(request);
}
}
}
}
public class MajorDemo extends Manager {
protected MajorDemo(String name) {
super(name);
}
@Override
public void requestApplications(Request request) {
if(request.getRequestType() == "请假" && request.getNumber()<= 5) {
System.out.println(name + ":" + request.getRequestContent() + " 数量" + request.getNumber() + " 被批准" );
}else {
if(superior != null) {
superior.requestApplications(request);
}
}
}
}
public class Main {
public static void main(String[] args) {
CommonManager jinli = new CommonManager("金利");
MajorDemo zongjian = new MajorDemo("宗剑");
GeneralManager zhongjingli = new GeneralManager("钟精励");
jinli.SetSuperior(zongjian);
zongjian.SetSuperior(zhongjingli);
Request request = new Request();
request.setRequestType("请假");
request.setRequestContent("小菜请假");
request.setNumber(1);
jinli.requestApplications(request);
Request request2 = new Request();
request2.setRequestType("请假");
request2.setRequestContent("小菜请假");
request2.setNumber(4);
jinli.requestApplications(request2);
Request request3 = new Request();
request3.setRequestType("加薪");
request3.setRequestContent("小菜请求加薪");
request3.setNumber(500);
jinli.requestApplications(request3);
Request request4 = new Request();
request4.setRequestType("加薪");
request4.setRequestContent("小菜请求加薪");
request4.setNumber(1000);
jinli.requestApplications(request4);
}
}
Mediator
类:abstract class Mediator {
//定义一个抽象的发送消息方法,得到同事对象和发送消息
public abstract void send(String message,Colleague colleague);
}
ConcreteMediator
类:public class ConcreteMediator extends Mediator{
public ConcreteColleague1 concreteColleague1;
public ConcreteColleague2 concreteColleague2;
public void setColleague1(ConcreteColleague1 value){
this.concreteColleague1 = value;
}
public void setColleague2(ConcreteColleague2 value){
this.concreteColleague2 = value;
}
@Override
public void send(String message, Colleague colleague) {
if(colleague == concreteColleague1){
concreteColleague2.notify(message);
}else{
concreteColleague1.notify(message);
}
}
}
Colleague
类:public class Colleague {
protected Mediator mediator;
// 构建方法,得到中介者对象
public Colleague(Mediator mediator){
this.mediator = mediator;
}
}
ConcreteColleague
类:public class ConcreteColleague1 extends Colleague {
public ConcreteColleague1(Mediator mediator) {
super(mediator);
}
public void send(String message){
this.mediator.send(message,this);
}
public void notify(String message){
System.out.println("同事1得到信息:"+message);
}
}
public class ConcreteColleague2 extends Colleague {
public ConcreteColleague2(Mediator mediator)
{
super(mediator);
}
public void send(String message)
{
this.mediator.send(message,this);
}
public void notify(String message)
{
System.out.println("同事2得到信息:"+message);
}
}
public class main {
public static void main(String[] args){
ConcreteMediator m =new ConcreteMediator();
ConcreteColleague1 c1 = new ConcreteColleague1(m);
ConcreteColleague2 c2 = new ConcreteColleague2(m);
m.setColleague1(c1);
m.setColleague2(c2);
c1.send("吃过饭了吗?");
c2.send("没有呢,你打算请客?");
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
成都创新互联是一家专业提供维西企业网站建设,专注与成都网站设计、网站建设、H5页面制作、小程序制作等业务。10年已为维西众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。