Solved

Class keeping track of own members vs not.

Posted on 2009-07-10
7
214 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with my python script 6 145
wordsWithout 49 79
base64 decode encode 12 96
java  and programming certification ? 4 64
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now