0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Singleton Pattern

Last updated at Posted at 2020-11-09

#Singleton Pattern
一つしかインスタンスを生成しない

このページでは以下を記載します
・Singleton Pattern サンプルコード

Design Pattarm MENU

以下のクラス構成で確認します

クラス 説明
singleton.class インスタンスを一つだけ生成する
user(Main.class) インスタンスを生成する
*user 他の開発者がこのパターンを利用する、という意味合いを含みます
singleton.class
class singleton{
  private static singleton singleton = new singleton();
  private singleton(){}
  public  static singleton newInstance(){return singleton;}
}
user(Main.class)
public static  void main(String[] args){
  singleton s1 =singleton.newInstance();
}}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?