Link to home
Create AccountLog in
Avatar of simondopickup
simondopickup

asked on

C++ Derived Classes

Hello,

I am currently building many containers to hold various types of information that is being extracted from logs. I have vectors and multisets to store the objects of certain classes that are being created from the parsing of the logs. For example, I have an ACTOR class that has attributes of name and address. However, I also want a CONVERSATION class to be an object of each ACTOR class, which i want to store in containers as they are created.
So I effectively want an object of an object - both of which will be stored in a container.

I am doing this because i want to be able to count the number of conversations per actor depending on certain attributes of the conversation object.

so for example i would create the new actor object within a mulitset using something like
actor_set.insert(actor(name, address, age)).

When i continue to parse the file and a conversation corresponding to the  actor.name is discovered, I want to insert a conversation object within the actor object and keep adding to it as more conversations are found.

If anyone understands what I am trying to do - but could offer a better alternative - I would appreciate the advice. I cant use arrays as I dont want to predefine the size.

Get it?? Sorry for the ambiguity ....:(

simondo
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

I understand what you're doing but not what the problem is. It seems like a reasonable object model to me.
Just a little thought : wouldn't a conversation involve 2 or more actors ?
SOLUTION
Avatar of wizzardofoz
wizzardofoz
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
>> but an array of GUID's referring to the conversations
How about just iterators into an STL cointainer? That's the more natural way to handle cross-container references in C++.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of simondopickup
simondopickup

ASKER

Evilrx contributed the most..in the end ;) - it has been enough to get me going.

Can someone look at my other open question!!!!!!!!!!!!!1 argghhhh

https://www.experts-exchange.com/questions/24391623/Scan-all-folders-within-a-directory.html
>> Storing (potentially) large strings in a set is inefficient.
The set is storing the smart pointers, not the conversations themselves.
>> The set is storing the smart pointers, not the conversations themselves.
Then how are you gong to do a lexical search?
I would iterate over the elements in the set and search within each element.
In any case it is best not to expose the datatype used for storing the conversations (be it a set, a map or something else) to the clients of the class since it is an implementation detail.
If searching in a set of smart pointers would turn out to be too slow (after running the profiler), it can be replaced with a more complex and efficient approach without breaking any code.

>> I would iterate over the elements in the set and search within each element.
But then you are ignoring one of the benefits of using a set, locating data in O(log N) time. Your solution will require O(N) time nd gains nothing for this cost.

>> In any case it is best not to expose the datatype used for storing the conversations
And yet you are doing exactly this by forcing the user of the set to know they have to iterate it because of the data type being used.

>> it can be replaced with a more complex and efficient approach without breaking any code.
I can be replced with what I suggested, which is not complex and yet is efficient.

I love it. Great value for points.

 Evilrx - why dont you have a Windows machine :S can you at least explain the 3 questions i asked in the post just from c++ knowledge?!!
>> Evilrx - why dont you have a Windows machine
I don't need one that's why :)

>> can you at least explain the 3 questions i asked in the post just from c++ knowledge?!!
I'll review and answer in the other thread
>> Your solution will require O(N) time nd gains nothing for this cost.
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." (Donald Knuth)

>> And yet you are doing exactly this...
I think you misunderstood. I refered to the client of the Actor class (i.e. another class using the Actor class). This client need not be aware of the storage type used internally by Actor.

>> I can be replced with what I suggested, which is not complex and yet is efficient.
You say it is not complex, which suggests that it is not simple either, right? (Keep It Short and Simple)
>> "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." (Donald Knuth)
Yes I too know this incorrectly attributed quote but there is a difference between premature optimizaion and good up-front design. In this case we are NOT talking about small efficiencies we are talking about a good and robust design that meets all the reuirements in an time efficient manner, without the need to add extra layers of complexity.

>> Keep It Short and Simple
It is simple!

I'm done with this, the discussion is now moot.

Sorry, just one fnal point from me, the following link discusses Hoare's Dictim (the original quote comes from Sir Charles Antony Richard Hoare, who invnted the Quick Sort). It goes on to explain why this quote is often misunderstood and, as such, why inexperienced programmers often go on to develop non-scalable solutions. This is, bascally, what I was eluding to above. Premaure optimization is often confused with good design.

http://www.cookcomputing.com/blog/archives/000084.html

Now I really am done with this :)
I fully agree with this post, but does this this warning about ignoring scalability apply here?
Choosing how to store conversations in the Actor class appears to be an implementation detail of the Actor class, not a system level decision.