Skip to main content
gamedev.net
🔒 Locked

OOP (Object Oriented Programming)

Started by Blade Runner Oct 14, 2001 at 9:08 PM 1 replies 300+ views
Original Post
Blade Runner
Blade Runner
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?
--------------------------I shall thrash his bloody head in, cut it from upon his shoulders, and as his blood flows effortlessly down my blade, I shall taste it's sweetness. Blade Runner’s Entertainment Nothing much right now...
Martee
Martee
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.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Shannon Barber
Shannon Barber
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
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.