Solved

Class keeping track of own members vs not.

Posted on 2009-07-10
7
215 Views
Last Modified: 2013-11-12
Hi,

My apologies - the topic title isn't exactly the best way to summarise this question, but I'm afraid it's the best I can come up with. What I'm curious about are the advantages and disadvantages to having a static class that allows the creation of members (stored within a static array/vector within the class) as to having a normal class that can be instantiated with whatever creating the object looking after the object?

Obviously one advantage is if the static class keeps track of its own members then there's no reason to pass members as there is with an instantiated class.

Thanks,
Uni
0
Comment
Question by:Unimatrix_001
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:Let_Me_Be
ID: 24827855
Actually there are many, many ways of tracking class instances. This particular case?

Well, it might be good if you for example want to provide a C API for a C++ objective code. This approach would be very natural (accessing object instances using some sort of ID).

Its hard to say, you didn't even specify the language. It might be just used as a walk around some language restrictions of some kind.
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24827881
Hi, I assumed that a design system like this may be language independent, as not, I'm looking from the POV of C++.
0
 
LVL 12

Expert Comment

by:Let_Me_Be
ID: 24827986
Such question are always very language specific. Language constructs, although similar, have very different implementations and implications in different languages.

OK, well, from the design point of view: if it fits, just use it.

From the effectiveness point of view? Well, that's a bit harder. If the objects are very small and for some reason you need to access them from the whole program (using stack is not sufficient), using a static array, or even a dynamically allocated array might prove faster.

But once again, its hard to say in general. In C++ specifically, if a correct language feature or construct is used wrongly, it might be have big speed impacts.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24828009
Hm, so essentially you're saying I'd need a specific example for any useful sort of comment regarding performance,effectiveness, etc?

Thanks,
Uni
0
 
LVL 12

Accepted Solution

by:
Let_Me_Be earned 500 total points
ID: 24828061
In this case yes. The construct is actually very specific, so if you want to speak about performance you need to see it in some context.

Keep in mind, once again, this has nothing to do with design decisions (if it fits, use it) and in many cases good design decision can be a bigger performance gain then any optimization.
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24828066
Ok, thank you. :)

Uni.
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31602283
:)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question