Archived

This topic is now archived and is closed to further replies.

Blade Runner

OOP (Object Oriented Programming)

Recommended Posts

I''m sure that someone in here has programmed using classes in MS VC++, but I have not so I came here to ask ask a question about classes. In OOP (Object Oriented Programming) how do you know what parts to declare as Private, Protected, or Public? Lets say this is my code... class Fire { public: void Shoot(void); private: void Grenade(void); protected: bool Darts(void); }; So what would be declared what, does it go by the number of times it is accessed or by weather or does it not matter?

Share this post


Link to post
Share on other sites
If a method is public, it can be accessed by anyone. In other words, make a method public if you expect people using your class to use that method. Private methods can only be accessed by other methods inside that class, or by methods in friend classes. Use private for methods which you want to hide from the outside world. Protected methods are similar to private, except that they can also be accessed by derived classes. Use protected when you want to keep stuff hidden from the user of the class, but you want to make that stuff available to derived classes.

Share this post


Link to post
Share on other sites
If you want to get into the OOP of things,

        
interface IMarine
{
public:
IFireArm* m_pPrimaryWeapon;
IFireArm* m_pSecondaryWeapon;
IGernades* m_pGernades;
};

interface IWeapon
{
public:
virtual const char* GetDesc()=0;
virtual const IAnimation GetFireAnnimation()=0;
};

interface IFireArm : public IWeapon
{
public:
virtual void PullTrigger()=0;
virtual void ReLoad()=0;
};

class CFireArm_M4
{
virtal const char* GetDesc(return "M4";)
virtual void PullTrigger()
{
m_pLoadedAmmo->Consume();
//other stuff...

}
virtual voif ReLoad()
{
//get get ammo from the clip list

// stick in m_pLoadedAmmo

}
private:
IAmmo* m_pLoadedAmmo;
std::list<IAmmo*> m_listAmmoClips;
};


off the top of my head, that's what I'd do

Edited by - Magmai Kai Holmlor on October 14, 2001 10:42:37 PM

Share this post


Link to post
Share on other sites