Cambios recientes

2008-11-16
2008-07-23
2008-07-10
2008-06-24
2008-05-24
2008-05-20

Últimos archivo liberados

This Project Has Not Released Any Files

Wiki Guide

Sidebar

  1. interface Unit
  2. {
  3. void attach();
  4. void detach();
  5. }

単純に三角と四角を描くことを考える

  1. 三角を描け();
  2. 四角を描け();

三角にtextureを貼る

  1. textureを有効();
  2. 三角を描け();
  3. textureを無効();
  4. 四角を描け();

三角と四角を回転させる

  1. 回転を有効();
  2. textureを有効();
  3. 三角を描け();
  4. textureを無効();
  5. 四角を描け();
  6. 回転を無効();

openglではこういったことはよくあることなのでinterface Unitを適用してみると

  1. 回転.attach();
  2. texture.attach();
  3. 三角.attach(); 三角.detach();
  4. texture.detach();
  5. 四角.attach(); 四角.detach();
  6. 回転.detach();

こうなる。形を変えてみると

  1. void draw(Unit[] units)
  2. {
  3. foreach (v; units) v.attach();
  4. foreach_reverse (v; units) v.detach();
  5. }
  6. draw([回転, texture, 三角]);
  7. draw([回転, 四角]);

コンテナとの相性がよくなり、コードが短くなって、可読性も高まる。