nginx_module_t
定義模塊,結(jié)構(gòu)體里有若干函數(shù)指針和擴(kuò)展字段,然后橋接實(shí)現(xiàn)了豐富多彩的 core、conf、event、stream、http 等功能模塊,搭建起整個(gè) Nginx 框架HandsetSoft
實(shí)現(xiàn)類:public abstract class HandsetSoft {
public abstract void run();
}
HandsetSoft
具體實(shí)現(xiàn)類:public class HandsetGame extends HandsetSoft {
@Override
public void run() {
System.out.println("運(yùn)行手機(jī)游戲");
}
}
public class HandsetAddressList extends HandsetSoft {
@Override
public void run() {
System.out.println("運(yùn)行手機(jī)通訊錄");
}
}
HandsetBrand
抽象類:public abstract class HandsetBrand {
protected HandsetSoft soft;
public void SetHandsetSoft(HandsetSoft soft) {
this.soft = soft;
}
public abstract void run();
}
HandsetBrand
擴(kuò)展抽象類: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() == "請(qǐng)假"){
System.out.println(name + ":" + request.getRequestContent() + " 數(shù)量" + request.getNumber() + " 被批準(zhǔn)" );
}else if(request.getRequestType() == "加薪" && request.getNumber()<= 500) {
System.out.println(name + ":" + request.getRequestContent() + " 數(shù)量" + request.getNumber() + " 被批準(zhǔn)" );
}else {
System.out.println(name + ":" + request.getRequestContent() + " 數(shù)量" + request.getNumber() + " 再說吧" );
}
}
}
public class MajorDemo extends Manager {
protected MajorDemo(String name) {
super(name);
}
@Override
public void requestApplications(Request request) {
if(request.getRequestType() == "請(qǐng)假" && request.getNumber()<= 5) {
System.out.println(name + ":" + request.getRequestContent() + " 數(shù)量" + request.getNumber() + " 被批準(zhǔn)" );
}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() == "請(qǐng)假" && request.getNumber()<= 5) {
System.out.println(name + ":" + request.getRequestContent() + " 數(shù)量" + request.getNumber() + " 被批準(zhǔn)" );
}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("鐘精勵(lì)");
jinli.SetSuperior(zongjian);
zongjian.SetSuperior(zhongjingli);
Request request = new Request();
request.setRequestType("請(qǐng)假");
request.setRequestContent("小菜請(qǐng)假");
request.setNumber(1);
jinli.requestApplications(request);
Request request2 = new Request();
request2.setRequestType("請(qǐng)假");
request2.setRequestContent("小菜請(qǐng)假");
request2.setNumber(4);
jinli.requestApplications(request2);
Request request3 = new Request();
request3.setRequestType("加薪");
request3.setRequestContent("小菜請(qǐng)求加薪");
request3.setNumber(500);
jinli.requestApplications(request3);
Request request4 = new Request();
request4.setRequestType("加薪");
request4.setRequestContent("小菜請(qǐng)求加薪");
request4.setNumber(1000);
jinli.requestApplications(request4);
}
}
Mediator
類:abstract class Mediator {
//定義一個(gè)抽象的發(fā)送消息方法,得到同事對(duì)象和發(fā)送消息
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;
// 構(gòu)建方法,得到中介者對(duì)象
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("沒有呢,你打算請(qǐng)客?");
}
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
成都創(chuàng)新互聯(lián)是一家專業(yè)提供維西企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、H5頁面制作、小程序制作等業(yè)務(wù)。10年已為維西眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。