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.

多数のFacade配下のクラスの利用をコントロールする。userはFacadeを通じてFacade配下のクラスを利用する

Design Pattarm MENU

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

package アクセス修飾子 クラス 説明
sample public facade.class facadeが管理する各クラスの呼び出し、利用をコントロール
sample default sam0.class~sam2.class int値を戻す
default public user(Main.class) facadeを利用してsam0.class~sam2.classを利用する

*user 他の開発者がこのパターンを利用する、という意味合いを含みます

facade.class
package sample;
public  class facade{
    int res;
    public facade(int condition){
        switch(condition){
          case  0 : res = new sam0().get();break; 
          case  1 : res = new sam1().get();break;
          default : res = new sam2().get();break;
        }
        this.res = res;
    }
    public int get(){return this.res;}
} 
sam01.class
package sample;
class sam0{ int get(){return 0;} }
class sam1{ int get(){return 1;} }
class sam2{ int get(){return 2;} }
user(Main.class)
import sample.facade;
class  Main {
  public static void main(String[] args){
    facade fd = new facade(8);
    System.out.println(fd.get());
  }
}
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?