.NETGURU
class design question
Messages   Related Types
This message was discovered on microsoft.public.dotnet.general.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

rodchar (VIP)
Hey all,

I read somewhere about the 7+-2 where that's a good number of properties to
have per class. What if all the fields are important? What do you do?

rodchar
Reply to this message...
 
    
Peter van der Goes
"rodchar" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

I'd really like to see the source for a statement like that! You're saying
that a class should have between 5 and 9 data members? I've never run across
such an assertion and have seen many classes with far more than 9 data
members, and have seen utility classes with none.
Design your class to provide the full set of characteristics and behaviors
appropriate for instantiated objects and don't worry about arbitrary limits.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Reply to this message...
 
    
Nick Malik
[Original message clipped]

The source is a paper published by George Miller in 1956 called "The magical
number seven plus or minus two" which deals with the ability of a person to
retain only a small number of distinct "Chunks" of discrete information in
short term memory.
http://www.well.com/user/smalin/miller.html

I am surprised and disheartened to hear Mr. Miller's paper taken so badly
out of context.

--- Nick

Reply to this message...
 
    
Peter van der Goes
"Nick Malik" <Click here to reveal e-mail address> wrote in message
news:DpQ1d.437634$%_6.217985@attbi_s01...
[Original message clipped]


Reply to this message...
 
    
JohnReb (VIP)
If the functionality of a class truly needs more properties, then I use them.
Guidelines are just that - guidelines; exceptions will occur.

If a class seems to be bloating, its worth taking a look at the design, but
breaking functionality that truly belongs in one class into several classes
is no better than putting everything in the main() method...

Best Regards,
John

"rodchar" wrote:

[Original message clipped]

Reply to this message...
 
    
rodchar (VIP)
Thanks everybody for the replies. If I may ask,
let's say you have a parent class and a child class, is it fine to have a
method in the parent class like RetrieveChildren?

"rodchar" wrote:

[Original message clipped]

Reply to this message...
 
    
Nick Malik
may not be that easy to write the method... unless you are using Reflection,
which is outside the normal behavior of an OO design.

What would this method do and why do you need it?
--- Nick

"rodchar" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
rodchar (VIP)
I'm just trying to display the data on a windows form and allow for editing.
So what I should do is let the client of the 2 classes instantiate a child
collection?

"Nick Malik" wrote:

[Original message clipped]

Reply to this message...
 
    
Nick Malik
Please illustrate your problem with an example or a more complete
description of what you are having trouble with.

I want to help, but it is difficult with such sparse data. All I know about
your application is:
a) you were given advice to limit the number of properties and methods
b) you want to know if it is OK to have a parent create a method called
"RetrieveChildren" (although I'm not sure what that method is supposed to
do).
c) you app is a windows app, not a web app.
d) your class holds data that users will edit. (Is the class derived from
Windows.Forms.Control ? )
e) clients will need to create more than one derived child class at a time.

That's not a lot to go on. I can imagine a couple of dozen completely
different designs that would meet these criteria.
Your specific question, asking about collections, implies that I can guess
which design you are using (assuming that you
aren't creative enough to have created a design that I haven't thought of...
I'd be a fool to assume that.)

Do you see the conundrum?

--- Nick

"rodchar" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I'm just trying to display the data on a windows form and allow for
editing.
[Original message clipped]

Reply to this message...
 
    
rodchar (VIP)
sorry for the confusion, ultimately i'm looking for class design ideas.
All i have is a simple window app that initially shows a datagrid of parent
records. When a user clicks on a record, it shows the record details in
another window. From there there's a button to view the child objects in
another datagrid. And the user should be able to update the parent and the
child records.

b) you want to know if it is OK to have a parent create a method called
"RetrieveChildren" (although I'm not sure what that method is supposed to
do).
Actually I wanted to know is if it was ok to have a method in the parent
class,not create one, called RetrieveChildren. I guess what I'm asking is who
is responsible for instaniating the child collection (the client (i.e. form1)
or the parent class)

"Nick Malik" wrote:

[Original message clipped]

Reply to this message...
 
    
Henk Verhoeven
Hi rodchar

I would rather approach the class from what you model vs. what is
mathematically the magic number.

If you model a real world situation, then you can most certainly not abide
by any "ratio", but you must abide by design , requirements and what you
model.

It requires all the properties, then use all of the properties. More typing,
but now you will have a class that perfectly represent your real world
scenario

Henk

"rodchar" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Windows.Forms.Control




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification