LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2010, 05:49 AM   #1
gozlemci
Member
 
Registered: Mar 2010
Location: Turkey
Posts: 35

Rep: Reputation: 0
seven data members


Hi There;
I've read "Code Complete" and the Author mentioned a principle :
"Be critical of classes that contain more than about seven data members"

There is a point that I can not understand is "data member". Is he mentioned a class that contains seven different type of variables, or seven variables in same type?
I mean, according to author, which class must I take care, Class1 or Class2 below?

Code:
public class Class1 
{

type1 var1
type2 var2
type3 var3
type4 var4
type5 var5
type6 var6
type6 var7

}
Code:
public class Class2
{
type1 var1,var2,var3,var4,var5,var6,var7
}
Thanks in advance.

Last edited by gozlemci; 12-01-2010 at 05:51 AM. Reason: False word
 
Old 12-01-2010, 07:25 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
both (according to the author)

Last edited by graemef; 12-01-2010 at 07:27 AM.
 
Old 12-01-2010, 07:28 AM   #3
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
I can not agree with this assumption. Every class should have that many data members as much as it needs.
 
Old 12-01-2010, 08:04 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by eSelix View Post
I can not agree with this assumption. Every class should have that many data members as much as it needs.
I agree with you but I think that the idea (which has some merit) is that if a class has more than a certain number of data members then you should question the class to see if it should be broken down into sub classes. Often that leads to moving the complexity out of the class and into the hierarchy.
 
Old 12-01-2010, 08:25 AM   #5
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 298

Rep: Reputation: 49
Quote:
Originally Posted by eSelix View Post
Every class should have that many data members as much as it needs.
Yes, but the original auther's point is to question that need. Or, more exactly, to give a hint as to when to question that need.

Which is very reasonable, just as a lot of indenting levels or very long functions are signs that a function probably better be divided into smaller units. (see charper 1 and 6 of Linux coding style guidelines).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we see all the LQ members raju.mopidevi LQ Suggestions & Feedback 10 03-22-2010 01:09 PM
Hello all members ! janndoone LinuxQuestions.org Member Intro 2 02-10-2010 05:08 AM
You can now Thank LQ Members jeremy LQ Suggestions & Feedback 82 07-17-2009 10:42 AM
How to initialize const data members in base classin cpp? milky.way Programming 1 11-24-2007 10:30 PM
Hello Members captain_hook LinuxQuestions.org Member Intro 1 06-19-2007 03:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration