ã2010年現在のアクセスレベルの限界 - プログラマーの脳みそã§ã¯public, protected, private, ããã±ã¼ã¸ãã©ã¤ãã¼ãã¨ããï¼ã¤ã®ã¢ã¯ã»ã¹ã¬ãã«ã§ã¯ãã¾ãè¡ããªãäºä¾ã¨ããè¦ç¹ã ã£ããã©ãä¾ã«æããDIã³ã³ããäºã ã¨ããã®ã¯ã¢ã¯ã»ã¹ã¬ãã«ã®ä¸åã¨ããããããã³ã³ã¹ãã©ã¯ã¿ã®ä¸åã¨æããã¹ãã ã
ã³ã³ã¹ãã©ã¯ã¿ã使ããªãã¤ã³ã¹ã¿ã³ã¹åå¾
ãJavaã®å ´åãã¤ã³ã¹ã¿ã³ã¹çæã¯ã³ã³ã¹ãã©ã¯ã¿ã«ãã£ã¦è¡ãããããã®ã¯ã©ã¹ã®å¤é¨ãããã¤ã³ã¹ã¿ã³ã¹ãå¾ããã¨ããå ´åã®ä¸çªåºæ¬çãªã¤ã³ã¹ã¿ã³ã¹åå¾æ¹æ³ã¯ãnew ã«ãã£ã¦ã¤ã³ã¹ã¿ã³ã¹ãæ°ãã«çæããæ¹æ³ã
ããããããã¨ãã°GoFãã¶ã¤ã³ãã¿ã¼ã³ã®Singletonã§ããã¨ãããããã¯Flyweightã§ããã¨ããè¿ãã¤ã³ã¹ã¿ã³ã¹ã常ã«newãããããã§ã¯ãªããæ¢åã®ã¤ã³ã¹ã¿ã³ã¹ã使ãåãã¦è¿ããããªä½ãã«ä½¿ç¨ã¨ããå ´åãã³ã³ã¹ãã©ã¯ã¿ã§ã¯ãæä¸ããªã®ã ãã³ã³ã¹ãã©ã¯ã¿ã¯æ°ãã«çæãããã¤ã³ã¹ã¿ã³ã¹ããè¿ããªããnew æ¼ç®åã§ã¯å¸¸ã«æ°åã®ã¤ã³ã¹ã¿ã³ã¹ãå¾ãããã
ãã¤ã³ã¹ã¿ã³ã¹ãå¾ãããã¨ããå ´åã«ããã¯ã©ã¹ã¯newã使ããããã¯ã©ã¹ã¯ã¤ã³ã¹ã¿ã³ã¹ãå¾ãããã®ã¡ã½ããã使ããã¨ãªã£ã¦ãã¾ã£ã¦ããã®ã2010å¹´ç¾å¨ã®Javaã®å®æ ã§ããã
宣è¨çãªã¤ã³ã¹ã¿ã³ã¹çæ
ãGUIã®ããã°ã©ã ããããã¨ããã人ãªãã°é層æ§é ãæã¤ãªãã¸ã§ã¯ãã®ã¤ã³ã¹ã¿ã³ã¹ã®çæã®é¢åãããã¯ããç¥ã£ã¦ããã®ã§ã¯ãªãã ããããJFrameãä½ã£ã¦å種è¨å®ãããJLabelãä½ã£ã¦å種è¨å®ããframeã«addãJTextFieldãä½ã£ã¦å種è¨å®ããframeã«addãJButtonãä½ã£ã¦å種è¨å®ããframeã«addâ¦
ããããæç¶ãåè¨èªãã¾ãä»ã®å ´åã¯Javaãªã®ã ããããã§è¨è¿°ããã¨ä»¥ä¸ã®ãããªæãã«ãªãã
import java.awt.BorderLayout; import java.awt.Font; import javax.swing.*; public class SwingSample { public static void main(String[] args) { JFrame frame = new JFrame("Swing!"); frame.setSize(200, 120); JLabel label = new JLabel("Hello"); label.setFont(new Font("Serif", Font.BOLD, 18)); frame.getContentPane().add(label, BorderLayout.NORTH); JTextField field = new JTextField("type..."); field.setFont(new Font("Serif", Font.PLAIN, 12)); frame.getContentPane().add(field, BorderLayout.CENTER); JButton button = new JButton("OK"); frame.getContentPane().add(button, BorderLayout.SOUTH); frame.setVisible(true); } }
ãè¿å¹´ã®GUIåãè¨èªã¯ãã®ããããæ¹åããããã«å®£è¨åã®æ§æãç¨æãããªã©ãã¦ãããã¤ã¾ããGUIã³ã³ãã¼ãã³ãã®é層æ§é ãçµã¿ç«ã¦ãã®ã«æç¶ãã¯ä¸è¦ã§ãã©ãã«ä½ãå ¥ãã¨ãã宣è¨ããããã°ãããããããç¹å®ã®ç®çã«ãã£ãæ§æãç¨æãããã¨ã§æç¶ãåã§ã³ã³ãã¼ãã³ããçµã¿ç«ã¦ãããã¯ããã«å¯èªæ§ããããªãããããã°ã©ãã³ã°ã¯æ¥½ã«ãªãã
ãFlex/AIRã®ActionScriptã«ãããMXMLã§ããã¨ããsilverlightã®XAMLã§ããã¨ããJavaFXã§ã®å®£è¨åæ§æã¨ããããã«ãããããã¦ãããã§ã¯å ã®Javaã®swingã§ã®ããã°ã©ã ã®å ãã¿ãJavaFXçã®ã½ã¼ã¹ãè¦ã¦ã¿ããã
import javafx.ui.*; var window = Frame { title:"JavaFX!" width:200 height:120 content:BorderPanel { top:Label { text:"Hello" font:new Font("Serif", "BOLD", 18) } center:TextField { value:"type..." font:new Font("Serif", "PLAIN", 12) } bottom:Button { text:"OK" } } }; window.visible = true;JavaFXによるGUIアプリケーションの作成 (2/3):CodeZine(コードジン)
ãã©ãã ããããGUIã³ã³ãã¼ãã³ãã®çµã¿ç«ã¦ã§éè¦ãªã®ã¯ã©ãã«ä½ãè¨å®ããããã§ãã£ã¦ãé çªã¯ããããæå³ãæããªããæç¶ãåè¨èªã¯é 次å¦çã¨ããåºæ¬ã®åºæ¬ãããã®ã ãã©ããããªãã®ã¯ã©ãã§ãããã
ãã¡ãªã¿ã«ãMXMLã¨XAMLã¯XMLå¼ã®æ§æãæ¡ç¨ãã¦ãããXMLãé層æ§é ã宣è¨ããã«ã¯æç¶ãåããããã¿ã¼ãªè¡¨ç¾ã ããã
ãããã§ã¯2010å¹´ç¾å¨ãæ¯è¼ççºéãã¦ããGUIã®å®£è¨åã¢ããã¼ããä¾ã«æãã¦è¦ã¦ã¿ãããããã宣è¨åã¨ããã®ã¯GUIã³ã³ãã¼ãã³ããæ§ç¯ããã ãã«ã¨ã©ã¾ããªããèªåãã¹ããªã©ã§é層æ§é ããã£ããªãã¸ã§ã¯ãã®ãã¹ããã¼ã¿ã宣è¨ããã®ã«è¾æãã¦ãã人ãå¤ãã ãããããããã·ãã¥ã¨ã¼ã·ã§ã³ã§ãå¹æãçºæ®ããã
ãããããç¹ã§ãGUIã³ã³ãã¼ãã³ãã®çæã«å¾ãããã¦ããªãJavaFXã®å®£è¨åæ§æã¯å¬ããããã¶ã¤ã³ã®é¨åãå¥ãã¡ã¤ã«ã«æ¬ãã ãããã¨ããè¦æãããã ãããããä¸é·ä¸çã ã¨ã¯æããã
DIã³ã³ããã«ããã³ã³ãã¼ãã³ãã®ç®¡ç
ããã¦ãåç½®ããé·ããªã£ãããDIã³ã³ããã宣è¨åã®ã³ã³ãã¼ãã³ãçæãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦æãããã¨ãããã¨ãã§ãããç¾è¡ã®Javaã«ã¯ãªãæ©è½ããã¬ã¼ã ã¯ã¼ã¯ã§è£ãããã¨ããæ³¥èãå®åæ´¾ã®ææ³ã«ãªã£ã¡ããã®ã ãã©ã
ãããã«XMLã§ã®é層æ§é ã®å®£è¨ã¯æç¶ãåããããã¿ã¼ã ã¨ãã£ããã ãããã³ã³ãã¼ãã³ãã®çµã¿ç«ã¦ã®è¨è¨å³ãXMLã«ãããã ãã¦ãDIã³ã³ããã§çæããã¨ããææ³ãã·ãã¥ã¨ã¼ã·ã§ã³ããæãã°ã¡ãªãããåºã¦ããã
ãã¾ããåããã©ãè¨ãæ¹ããããã©ãã¡ãªããããã¡ãªããããããã§ææ¾ãã«ä¸æ³ã¨ããããã«ã¯è¡ããªãã¦ãçµæ§ã·ãã¥ã¨ã¼ã·ã§ã³ãé¸ã°ãªãã¡ããããªããããããæå³ã§ç¾è¡ã®DIã³ã³ããã¨ããã®ã¯é渡æã®æè¡ã ã¨æãããããããã¹ã¤ã«å®£è¨åã ããDIã³ã³ããã®ã¡ãªããã§ã¯ãªãã®ã ãã©ã宣è¨åæ§æã¨ã¢ã¹ãã¯ãæåãæ´åãããè¨èªããã£ããªããDIã³ã³ããã£ã¦ãããªããï¼ã£ã¦æãããã§ããããã
ã¤ã³ã¹ã¿ã³ã¹çæã¨ããã¡ã¿ãªè¦ç¹
ããã¦ãããã¾ã§
ã¨ãã£ãã¤ã³ã¹ã¿ã³ã¹ã®çæã«ã¾ã¤ãããã®ãè¦ã¦ããããã ãã©ãããããçµ±ä¸çã«æ±ããããã¡ã¿ãªã³ã³ã¹ãã©ã¯ã¿æ§ã®æ¦å¿µãå¿ è¦ã ã¨åã¯èãã¦ãã¦ãããããã°ããã«ã¢ã¹ãã¯ãæåãç¹ãè¾¼ããããããªããªãã¦å¦æ³ãããããã¦ããã¨ããã
ãåç´ã«ã¯ç¹å®ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãè¿ããã®ããã¹ã¦åæååã£ã¦ã¾ã¨ãã¡ãã£ããã©ãã ããï¼ã£ã¦ã®ã¯ããã®ã ãã©ãã¾ã ããããæ¡ã®è©ä¾¡ãã§ãã¦ãªãã
ã2010年代ã®è¨èªã¯ãã®ãããã解決ãã¦æ¬²ãããã®ã ãã