Java Programming

function pool

tomato13 2008. 11. 13. 08:01

C/C++에서는 function pointer를 사용하여 function에 대한 repository를 구성할 수 있을 듯 하다. Java의 경우 Container라는 class를 상속받아 function pool class를 구성할 수 있으며 Method라는 class로 각각의 function을 제어할 수 있는 듯 하다. 아직 구체적으로는 잘 모르겠으나 예제 프로그램만을 간단하게 옮겨본다.

    

public static void main(String[] args) {

        CVariousFunctions l_Container = new CVariousFunctions();        

        Class l_class = l_Container.getClass();

        int l_nCnt = 0;

        

        Method[] l_m = l_class.getDeclaredMethods();

        

        for(; l_nCnt<l_m.length; l_nCnt++)  {

            try {

                l_m[l_nCnt].invoke(l_Container, new Object[]{});


            } catch (IllegalArgumentException e) {

                    e.printStackTrace();

            } catch (IllegalAccessException e) {

                    e.printStackTrace();

            } catch (InvocationTargetException e) {

                    e.printStackTrace();

            }

        }

    }