Solved

Class keeping track of own members vs not.

Posted on 2009-07-10
7
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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…
Simple Linear Regression

691 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