1. 程式人生 > 實用技巧 >.net core 傳送郵件

.net core 傳送郵件

工廠方法模式(Factory Method),定義一個建立物件的介面,讓子類決定例項化哪一個類。工廠方法使一個類的實列化延遲到其子類。

示意圖程式碼如下:

1 public abstract class Product {
2     public abstract void show();
3 }
Product
1 public class ConcreteProduct extends Product {
2 
3     @Override
4     public void show() {
5         System.out.println("ConcreteProduct...show....");
6 7 } 8 9 }
ConcreteProduct
1 public abstract class Creator {
2     public abstract Product factoryMethod();
3 }
Creator
1 public class ConcreteCreator extends Creator {
2 
3     @Override
4     public ConcreteProduct factoryMethod() {
5         return new ConcreteProduct();
6 
7
} 8 9 }
ConcreteCreator
1 public class TestFactory {
2     public static void main(String[] args) {
3         Creator c = new ConcreteCreator();
4         ConcreteProduct pro = (ConcreteProduct) c.factoryMethod();
5         pro.show();
6     }
7 }
test