国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - java 單例模式和工廠模式實例詳解

java 單例模式和工廠模式實例詳解

2020-09-10 14:22wuxiao5570 Java教程

這篇文章主要介紹了Java設計模式編程中的單例模式和簡單工廠模式以及實例,使用設計模式編寫代碼有利于團隊協作時程序的維護,需要的朋友可以參考下

單例模式根據實例化對象時機的不同分為兩種:一種是餓漢式單例,一種是懶漢式單例

私有的構造方法

指向自己實例的私有靜態引用

以自己實例為返回值的靜態的公有的方法

餓漢式單例

java" id="highlighter_689713">
?
1
2
3
4
5
6
7
public class Singleton {
  private static Singleton singleton = new Singleton();
  private Singleton(){}
  public static Singleton getInstance(){
    return singleton;
  }
}

懶漢式單例

?
1
2
3
4
5
6
7
8
9
10
public class Singleton {
  private static Singleton singleton;
  private Singleton(){}
  public static synchronized Singleton getInstance(){
    if(singleton==null){
      singleton = new Singleton();
    }
    return singleton;
  }
}<br>

工廠方法模式代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
interface IProduct {
   public void productMethod();
 }
 class Product implements IProduct {
   public void productMethod() {
     System.out.println("產品");
   }
 }
 interface IFactory {
   public IProduct createProduct();
 }
 class Factory implements IFactory {
   public IProduct createProduct() {
     return new Product();
   }
 }
 public class Client {
   public static void main(String[] args) {
     IFactory factory = new Factory();
     IProduct prodect = factory.createProduct();
     prodect.productMethod();
   }
 }

抽象工廠模式代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
interface IProduct1 {
  public void show();
}
interface IProduct2 {
  public void show();
}
class Product1 implements IProduct1 {
  public void show() {
    System.out.println("這是1型產品");
  }
}
class Product2 implements IProduct2 {
  public void show() {
    System.out.println("這是2型產品");
  }
}
interface IFactory {
  public IProduct1 createProduct1();
  public IProduct2 createProduct2();
}
class Factory implements IFactory{
  public IProduct1 createProduct1() {
    return new Product1();
  }
  public IProduct2 createProduct2() {
    return new Product2();
  }
}
public class Client {
  public static void main(String[] args){
    IFactory factory = new Factory();
    factory.createProduct1().show();
    factory.createProduct2().show();
  }
}

希望本文對各位朋友有所幫助

原文鏈接:http://blog.csdn.net/wuxiao5570/article/details/70154159

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 一级片黄 | 久久久免费 | 欧美日韩在线观看一区二区 | 人人射av| 99r精品在线 | 成人妇女免费播放久久久 | 欧美性久久 | 日韩国产 | 亚洲一区二区在线视频 | 亚洲免费二区 | 亚洲一区二区精品视频 | 性视频一区二区 | 三级成人在线 | 免费视频成人国产精品网站 | 午夜精品久久久久久久白皮肤 | 天天草天天干 | 超碰国产在线 | 做a视频| 在线小视频国产 | ...99久久国产成人免费精品 | 成人亚洲精品777777大片 | 中文字幕亚洲一区 | 亚洲人成网站999久久久综合 | 在线播放国产一区二区三区 | 国产精品永久免费视频 | 日韩精品成人 | 亚洲视频在线免费观看 | 欧美不卡在线 | 国内精品久久久久久中文字幕 | 黄色av网站在线观看 | 日本一区二区三区四区 | 欧洲一区二区三区精品 | 日操 | 国产精品久久久久久久免费大片 | 精品综合久久久 | 性激烈欧美三级在线播放狩猎 | 一级片免费在线观看视频 | 日韩欧美亚洲精品 | 精品国产99 | 国产成人一区二区三区 | 成人婷婷网色偷偷亚洲男人的天堂 |