Factory mode of operation

1. The factory class constructor necessarily need to privatize it, and why?

  Not necessarily. There are public see the source code modified, the reasons can not describe myself

2. DESIGN Factory payment services scenario, comprising a cross-border payment, Po, micro-letters, pay CUP and draw class diagram.

public interface IPayFactory {

public IPayMethod createPayMethod();

}

public interface IPayMethod {

public void prePay();

public void pay();

public void afterPay();
}

ZfbPayMethod the implements IPayMethod {class public 
@Override
public void Prepay () {
System.out.println ( "Alipay before preparation");
}

@Override
public void Pay () {
System.out.println ( "Alipay");
}

@override
public void afterPay () {
System.out.println ( "Alipay payment operation: push message to the user");
}
}

WechatPayMethod the implements IPayMethod {class public 
@Override
public void Prepay () {
System.out.println ( "micro-channel pay before preparation");
}

@Override
public void Pay () {
System.out.println ( "micro-payment letter");
}

@override
public void afterPay () {
System.out.println ( "micro-channel after the payment operation: push message to the user");
}
}

UnionPayMethod the implements IPayMethod {class public 
@Override
public void Prepay () {
System.out.println ( "Preparation for payment CUP");
}

@Override
public void Pay () {
System.out.println ( "payment CUP");
}

@override
public void afterPay () {
System.out.println ( "CUP after payment operation: push message to the user");
}
}

InternationalPayMethod the implements IPayMethod {class public 
@Override
public void Prepay () {
System.out.println ( "cross-border payment before preparation");
}

@Override
public void Pay () {
System.out.println ( "cross-border payment") ;
}

@Override
public void afterPay () {
System.out.println ( "border after payment operation: push message to the user");
}
}

public class ZfbPayFactory implements IPayFactory {
@Override
public IPayMethod createPayMethod() {
return new ZfbPayMethod();
}
}

the Test class {public 

public static void main (String [] args) {
IPayFactory new new ZfbPayFactory Factory = ();
IPayMethod payMethod factory.createPayMethod = ();
payMethod.prePay ();
payMethod.pay ();
payMethod.afterPay ();
}
}

UML diagram: teacher my idea settings plugins below why no UML Support

Guess you like

Origin www.cnblogs.com/it-szp/p/12359746.html