Phantom Programming
Moderator: Coders of Rage
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Phantom Programming
Ah, so you're already to the object-oriented goodness.The Phantom wrote:Can someone explain "accessors method"?
Sure, I'll explain:
Okay, first you must realize that there are private and public members of classes in C++. It is ALWAYS good to have variables and stuff private. (Don't ask me why, I never do it. But then again, I'm not exactly the greatest programmer :? )
Let's say that we had this here cat class:
Code: Select all
class Cat {
private:
int age;
};
Code: Select all
class Cat {
public:
int GetAge() {
return age;
}
private:
int age = 4;
};
Code: Select all
#include<iostream>
class Cat {
public:
int GetAge() {
return age;
}
private:
int age = 4;
};
void main() {
Cat Frisky; //Creating a new object of the cat class named "Frisky"
std::cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.\n";
}
If there is anything you want me to clarify, please ask.
Last edited by Falco Girgis on Tue Sep 07, 2004 8:04 pm, edited 3 times in total.
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
There's a couple ideas behind it
1) A good rule to follow with object-oriented programming is to program by modeling real things.
2) The functions are so it becomes impossible to set variables to incorrect values, esp. if you're using user-input for it. You can't error check with a basic assignment operator. Basically, the concept is that a class should be in control of all of its own stuff, instead of spreading the control for that around the program, or not having any control (model real things).
There. That's almost what I want to say.
3) It's consistent. You'll definitely need to error-check at least some of your variables. This saves you from having to go, "does this variable need value checking, or is there a function somewhere...?"
4) Besides any super-important reason I may have missed, I find it's just a good, easy convention to follow. Esp. since I do easy-to-remember things such as:
(Eventually! I'll get to the code-formatting eventually! Hold your horses... at least until the end of the week. :) )
1) A good rule to follow with object-oriented programming is to program by modeling real things.
2) The functions are so it becomes impossible to set variables to incorrect values, esp. if you're using user-input for it. You can't error check with a basic assignment operator. Basically, the concept is that a class should be in control of all of its own stuff, instead of spreading the control for that around the program, or not having any control (model real things).
There. That's almost what I want to say.
3) It's consistent. You'll definitely need to error-check at least some of your variables. This saves you from having to go, "does this variable need value checking, or is there a function somewhere...?"
4) Besides any super-important reason I may have missed, I find it's just a good, easy convention to follow. Esp. since I do easy-to-remember things such as:
Code: Select all
class TheClass {
int [u]theSuperVariable[/u];
public:
void set[u]TheSuperVariable[/u](int value);
int get[u]TheSuperVariable[/u]();
};
Last edited by MarauderIIC on Tue Sep 07, 2004 8:27 pm, edited 1 time in total.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
Thats funny, I just did it on my first try. Anyway, here's the site. http://www.libsdl.org/index.php
Just scroll down to downloads.
Just scroll down to downloads.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON