Quote:Original post by Jiia
I almost forgot to ask one other question. Why derive classes as public? As in CCharacter : public CObject. What happens when you derive them private or protected? Again, sorry if this is a dumb question.
;-)
Quote:Original post by Jiia
I almost forgot to ask one other question. Why derive classes as public? As in CCharacter : public CObject. What happens when you derive them private or protected? Again, sorry if this is a dumb question.
Quote:Original post by snk_kid
Maybe your using the wrong levels of abstraction, i see having CObject type which is the root of all types in a type hierarchy not very useful at all to be honest, it's to abstract to be put into any good use, you end up stuffing data and pushing functionality there where it doesn't actually make any sense.
Quote:Original post by snk_kid
solution look at the standard library bitset [www.sgi.com] and prefer using that instead.
Quote:Original post by snk_kidQuote:Original post by Jiia
But protected is still very useful to include tasks for that class to run on itself. This really does make a lot of sense.
I'm not sure what your saying here.
Quote:Original post by JiiaQuote:Original post by snk_kid
Maybe your using the wrong levels of abstraction, i see having CObject type which is the root of all types in a type hierarchy not very useful at all to be honest, it's to abstract to be put into any good use, you end up stuffing data and pushing functionality there where it doesn't actually make any sense.
I'm not sure what you mean. CObject represents a map based object. I don't see it as abstract at all. My point was to allow any number of map object types to be juggled around in all of my routines without ever really knowing or caring what is what. Most routines treat all map objects exactly the same, but their internal behavior is what makes them different.
Quote:Original post by Jiia
Thanks, but templated classes make me rather ill. And I'm not sure how this would help me, as it is the concept I'm asking about, not bitflags.
class CBitFlags;class CObject { ... CBitFlags FStatus; ...protected: const CBitFlags& getFlags() const { return FStatus; } CBitFlags& getFlags() { return FStatus; }public: virtual ~CObject() {}};struct CCharacter : public CObject { void TakeHealth(int value) { HurtMe(value); if(GetHealth() < 0) getFlags().TurnOn(STATUS_DEAD); }};
Quote:
If I may speak for Jiia, protected member functions are a possible way to implement callbacks. Example, you can publish a "MessagePump" framework class, and give it a protected virtual function OnIdle. The default implementation does nothing, but people may derive from "MessagePump" and implement their own version of OnIdle. The base class code will then call the derived function during its normal processing.
That being said, I wouldn't do anything this way anymore; I'd probably leave it to functors which would get registered with the class, and publish default functors with my nifty MessagePump.
Quote:Original post by Jiia
No, I don't derive everything from one type. Kind of pointless, really. CObject only has about 4 or 5 derived children.
In my opinion, GetFlags().TurnOn(STATUS_DEAD) is much uglier than having such protected member variables. Not to mention that functions need to be made to return every interface implimented.
In cases such as this, where the data itself is an interface, I don't understand the point of hiding the data in the first place. I'm not saying it's right, but I'm saying I don't understand why it's wrong.
Quote:Originally by snk_kid
encapsulate the variant/variation.
Quote:Original post by Jiia
I don't see a big difference between an interface data member and a group of member functions.
Quote:Original post by Jiia
No data can be modified directly.
Quote:Original post by Jiia
But you still wouldn't always want outside code to be able to call functions of the interfaces, just as you wouldn't want them to be able to call member functions.
Quote:Original post by Jiia
You don't agree that this situation happens, often?
A) All or most derived types of the base class must perform a task the exact same way.
B) That task may be implimented in different situations / at different times for each derived type. The tasks may be proceeded and followed by other tasks unique to each type. ie: The base class does not know when the tasks must be executed.
C) No outside routines should ever be allowed to run the tasks, as it would screw up the whole flow of things.
If code is broken up properly, there should be quite a few medium sized functions and interfaces which perform individual tasks. Where do I put these functions and interfaces?