472,958 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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
Jul 25 '08 #1
7 3891
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.
Jul 25 '08 #2
On Jul 25, 4:52*pm, Immortal Nephi <Immortal_Ne...@satx.rr.comwrote:
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. Comprehensibility, 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:

http://www.parashift.com/c++-faq-lit...d-objects.html
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
Jul 25 '08 #3
Immortal Nephi <Im************@satx.rr.comwrote:
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?
Jul 25 '08 #4
On Jul 25, 4:58*pm, "Daniel T." <danie...@earthlink.netwrote:
Immortal Nephi <Immortal_Ne...@satx.rr.comwrote:
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.InputCommand("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
Jul 26 '08 #5
Immortal Nephi wrote:
On Jul 25, 4:58 pm, "Daniel T." <danie...@earthlink.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.
Jul 26 '08 #6
Immortal Nephi <Im************@satx.rr.comwrote:
"Daniel T." <danie...@earthlink.netwrote:
Immortal Nephi <Immortal_Ne...@satx.rr.comwrote:
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?
Jul 26 '08 #7
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
Jul 31 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wenjie | last post by:
Hello, I read someone posted assertions that even the (public) member function is not static, there are probably only one copy of the code in the executable. Then except the...
4
by: 0to60 | last post by:
I don't know if I have that terminology right, but does anyone know if static member functions (or free standing functions for that matter) are any less overhead than actual member functions that...
2
by: Thomas Matthews | last post by:
Hi, I have a hierarchy of classes and would like to create an array of pointers to member functions that could also contain pointers to the parent member functions as well. What is the syntax...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
12
by: Anthony Jones | last post by:
Just a bit of background: I'm one of a group of FORTRAN programmers, looking to switch to C++. We are trying to write a few simple examples to demonstrate the power of the language to our manager,...
22
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
13
by: JohnQ | last post by:
The implementation of classes with virtual functions is conceptually easy to understand: they use vtables. Which begs the question about POD structs: how are they associated with their member...
2
by: Angus | last post by:
I have a member function, int GetLogLevel() which I thought I should change to int GetLogLevel() const - I made the change and it works fine. But in the function I am creating buffers and of...
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.