Too many member functions?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Immortal Nephi

    Too many member functions?

    My project grows large when I put too many member functions into one
    class. The header file and source code file will have approximately
    50,000 lines when one class contains thousand member functions. Is it
    normal how C++ Compiler can compile large class without any problem?
    Didn't C++ Compiler have rules to limit the number of member
    functions?

    One big object has complex operations how member variables and member
    functions can be manipulated according to my design. I put almost
    4,000 member functions inside one class. The class with 4,000 member
    functions is compiled without any problems and it runs very well.

    Can you do your best judgment? Is the practice best if I write one
    large object? Please note that only very few 5-10 member functions
    are public and other all thousand member functions are private.

    Here is an example

    // header
    class Obj
    {
    public:
    Obj();
    ~Obj();
    void Run();

    private:
    void mfunc1();
    void mfunc2();
    ......
    ......
    ......
    void mfunc4000();
    }

    // source
    void Obj::mfunc1()
    {
    }
    .....
    .....
    .....
    void Obj::mfunc4000( )
    {
    }

    These thousand member functions are like one big vtable pointer.
    One big member function pointer array can be used to access all
    thousand functions like this p_mfunc[xx][xx][xx](); This is neat when
    I allow to group thousands functions into main functions, sub-
    functions, and sub-sub-functions.
    Are you sure that it is worth best practice? You are prepared to
    do future project while you are working right now as I do.

    Nephi
  • Ian Collins

    #2
    Re: Too many member functions?

    Immortal Nephi wrote:
    My project grows large when I put too many member functions into one
    class. The header file and source code file will have approximately
    50,000 lines when one class contains thousand member functions. Is it
    normal how C++ Compiler can compile large class without any problem?
    Didn't C++ Compiler have rules to limit the number of member
    functions?
    >
    One big object has complex operations how member variables and member
    functions can be manipulated according to my design. I put almost
    4,000 member functions inside one class. The class with 4,000 member
    functions is compiled without any problems and it runs very well.
    >
    Can you do your best judgment? Is the practice best if I write one
    large object? Please note that only very few 5-10 member functions
    are public and other all thousand member functions are private.
    >
    That's seldom a good idea and it's definitely a short cut to
    unmaintainable code.

    Try and keep your classes small and focused on a particular task. Once
    a class stars to do too much, it has lost its focus. Except where I'm
    implementing a standard interface, I seldom have more than a dozen
    member functions (or data members) in a class. The member functions are
    also kept to around a dozen lines.

    Once a class gets beyond this, factor out some functionality to a new
    class. Once a function gets too long, factor out some functionality to
    a new function.

    --
    Ian Collins.

    Comment

    • mlimber

      #3
      Re: Too many member functions?

      On Jul 25, 4:52 pm, Immortal Nephi <Immortal_Ne... @satx.rr.comwro te:
      My project grows large when I put too many member functions into one
      class.  The header file and source code file will have approximately
      50,000 lines when one class contains thousand member functions.  Is it
      normal how C++ Compiler can compile large class without any problem?
      Didn't C++ Compiler have rules to limit the number of member
      functions?
      The is a QOI issue, not a standards issue.
      One big object has complex operations how member variables and member
      functions can be manipulated according to my design.  I put almost
      4,000 member functions inside one class.  The class with 4,000 member
      functions is compiled without any problems and it runs very well.
      [snip]

      And there are programs with 10000 lines of spaghetti code running fine
      as well, but running well is not the only criterion for a good
      program. Comprehensibili ty, maintainability , fragility, testability,
      etc. also need to be considered. Encapsulation and data hiding are
      tools we use to manage complexity. You have a chainsaw available; why
      use the hacksaw? See any book on OO programming and/or these FAQs:


      These thousand member functions are like one big vtable pointer.
      One big member function pointer array can be used to access all
      thousand functions like this p_mfunc[xx][xx][xx](); This is neat when
      I allow to group thousands functions into main functions, sub-
      functions, and sub-sub-functions.
      There are other ways to do this than a morbidly obese interface.

      Cheers! --M

      Comment

      • Daniel T.

        #4
        Re: Too many member functions?

        Immortal Nephi <Immortal_Nephi @satx.rr.comwro te:
        My project grows large when I put too many member functions into one
        class. The header file and source code file will have approximately
        50,000 lines when one class contains thousand member functions. Is it
        normal how C++ Compiler can compile large class without any problem?
        Didn't C++ Compiler have rules to limit the number of member
        functions?
        >
        One big object has complex operations how member variables and member
        functions can be manipulated according to my design. I put almost
        4,000 member functions inside one class. The class with 4,000 member
        functions is compiled without any problems and it runs very well.
        >
        Can you do your best judgment? Is the practice best if I write one
        large object? Please note that only very few 5-10 member functions
        are public and other all thousand member functions are private.
        >
        Here is an example
        >
        // header
        class Obj
        {
        public:
        Obj();
        ~Obj();
        void Run();
        >
        private:
        void mfunc1();
        void mfunc2();
        ......
        ......
        ......
        void mfunc4000();
        }
        >
        // source
        void Obj::mfunc1()
        {
        }
        ....
        ....
        ....
        void Obj::mfunc4000( )
        {
        }
        >
        These thousand member functions are like one big vtable pointer.
        One big member function pointer array can be used to access all
        thousand functions like this p_mfunc[xx][xx][xx](); This is neat when
        I allow to group thousands functions into main functions, sub-
        functions, and sub-sub-functions.
        Are you sure that it is worth best practice? You are prepared to
        do future project while you are working right now as I do.
        How many member-variables are there in this class? How many of these
        member-functions use all of the member-variables? How many of them don't
        use any of the member-variables?

        Comment

        • Immortal Nephi

          #5
          Re: Too many member functions?

          On Jul 25, 4:58 pm, "Daniel T." <danie...@earth link.netwrote:
          Immortal Nephi <Immortal_Ne... @satx.rr.comwro te:
          My project grows large when I put too many member functions into one
          class.  The header file and source code file will have approximately
          50,000 lines when one class contains thousand member functions.  Is it
          normal how C++ Compiler can compile large class without any problem?
          Didn't C++ Compiler have rules to limit the number of member
          functions?
          >
          One big object has complex operations how member variables and member
          functions can be manipulated according to my design.  I put almost
          4,000 member functions inside one class.  The class with 4,000 member
          functions is compiled without any problems and it runs very well.
          >
          Can you do your best judgment?  Is the practice best if I write one
          large object?  Please note that only very few 5-10 member functions
          are public and other all thousand member functions are private.
          >
          Here is an example
          >
          // header
          class Obj
          {
          public:
               Obj();
               ~Obj();
               void Run();
          >
          private:
               void mfunc1();
               void mfunc2();
               ......
               ......
               ......
               void mfunc4000();
          }
          >
          // source
          void Obj::mfunc1()
          {
          }
          ....
          ....
          ....
          void Obj::mfunc4000( )
          {
          }
          >
               These thousand member functions are like one big vtable pointer.
          One big member function pointer array can be used to access all
          thousand functions like this p_mfunc[xx][xx][xx]();  This is neat when
          I allow to group thousands functions into main functions, sub-
          functions, and sub-sub-functions.
               Are you sure that it is worth best practice?  You are prepared to
          do future project while you are working right now as I do.
          >
          How many member-variables are there in this class? How many of these
          member-functions use all of the member-variables? How many of them don't
          use any of the member-variables?- Hide quoted text -
          >
          Well, you may guess right, but not at all. You can use 100
          member variables. Four thousand member functions have different
          operations and states while they manipulate 100 member variables. You
          are very careful to design a large class. You make sure that extra
          member variables and member functions are not used or they are not
          written in C++ source code.
          The design of class is ideal to have thousand commands. Thousand
          commands are used to manipulate robot or any simulator project. You
          can define class in main function. You type few commands using cin
          keyword. Then run class like this Object obj; obj.InputComman d("Move
          arm"); obj.Run(); etc. You do not need to worry thousands member
          functions when they are defined in private. They can run to process
          complex operations and states. You used Object obj; to be loaded from
          large static library or dynamic library.
          Does I answer your question? I only need to know if C++ Compiler
          has rules to limit the number of member functions. C++ Compiler might
          fail on other machines such as 16 bit machine because large vtable
          pointer does not have sufficient memory. On all x86 machines and
          other machines using 32 bit and 64 bit will run fine when C++ Compiler
          is compiled successfully. It is my concern of memory issues.
          I think that between 16KB and 2 MB size of vtable should be
          sufficient. On 32 bit machine, 4000 member functions + 100 member
          variables times 4 bytes and vtable has 16KB size.

          Nephi

          Comment

          • Ian Collins

            #6
            Re: Too many member functions?

            Immortal Nephi wrote:
            On Jul 25, 4:58 pm, "Daniel T." <danie...@earth link.netwrote:
            >How many member-variables are there in this class? How many of these
            >member-functions use all of the member-variables? How many of them don't
            >use any of the member-variables?- Hide quoted text -
            >>
            Well, you may guess right, but not at all. You can use 100
            member variables. Four thousand member functions have different
            operations and states while they manipulate 100 member variables. You
            are very careful to design a large class. You make sure that extra
            member variables and member functions are not used or they are not
            written in C++ source code.
            No, you should be very careful *not* to design such a large class. If
            you do everything in one class, you may as well not bother with the
            class at all.

            --
            Ian Collins.

            Comment

            • Daniel T.

              #7
              Re: Too many member functions?

              Immortal Nephi <Immortal_Nephi @satx.rr.comwro te:
              "Daniel T." <danie...@earth link.netwrote:
              Immortal Nephi <Immortal_Ne... @satx.rr.comwro te:
              How many member-variables are there in this class? How many of
              these member-functions use all of the member-variables? How many
              of them don't use any of the member-variables?
              >
              Well, you may guess right, but not at all. You can use 100 member
              variables. Four thousand member functions have different
              operations and states while they manipulate 100 member variables.
              You are very careful to design a large class. You make sure that
              extra member variables and member functions are not used or they
              are not written in C++ source code.
              Does each of the 4 thousand member-functions use all of the 100
              member-variables?
              I only need to know if C++ Compiler has rules to limit the number
              of member functions. C++ Compiler might fail on other machines
              such as 16 bit machine because large vtable pointer does not have
              sufficient memory. On all x86 machines and other machines using 32
              bit and 64 bit will run fine when C++ Compiler is compiled
              successfully. It is my concern of memory issues. I think that
              between 16KB and 2 MB size of vtable should be sufficient. On 32
              bit machine, 4000 member functions + 100 member variables times 4
              bytes and vtable has 16KB size.
              Are all these member-functions virtual?

              Comment

              • baalbek

                #8
                Re: Too many member functions?

                Immortal Nephi wrote:
                <a lengthy explanation of a 1000 member method class>

                Nephi, please, PLEASE DO NOT design classes like this!

                Goddamn man, I'm almost thinking you are spamming this ng, for some
                strange reason.

                Break down your mega-class into smaller, more "focused" classes, each
                class having a more limited responsibility.

                Where on earth have you picked up your object oriented skills? Just
                wondering, so I do not send my kids to this place!

                Regards,
                baalbek

                Comment

                Working...