Thread: Object Oriented Programming

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    34

    Object Oriented Programming

    hello.

    im reading the tutorial's on c++ programming i just got to the one on object oriented programming and i don't get it at all
    if any 1 can give me some more info on it i would relly love that
    thankes for your time

  2. #2

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by eric123
    hello.

    im reading the tutorial's on c++ programming i just got to the one on object oriented programming and i don't get it at all
    if any 1 can give me some more info on it i would relly love that
    thankes for your time
    A lot of times when you are first learning programming concepts, you won't understand why you would want to do whatever it is you are reading about. However, when you're first learning a new concept, just think of it as a neat trick you can perform. Don't worry about why you would ever use the concept, just learn the mechanics of how to do it. Later, when you've written enough programs and have done enough exercises you will begin to understand more and more, and then the "why's" will slowly come into focus.

    Here is an example of object oriented programming(OOP):
    Code:
    #include<iostream>
    using namespace std;
    
    class Duck
    {
    public:
    	void quack()
    	{
    		cout<<"quack, quaaaaack."<<endl;
    	}
    
    	void fly()
    	{
    		cout<<"flap, flap, flap"<<endl;
    	}
    };
    
    int main()
    {
     
    	Duck myDuck;
    
    	myDuck.quack();
    	myDuck.fly();
    
    	return 0;
    }
    Last edited by 7stud; 11-29-2005 at 06:25 AM.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Assuming this is your first programming language, this is going to be difficult because you don't know any non-OOP languages to compare it to. Like 7stud says, don't worry about it! This could be an advantage, as OOP will seem like the natural way to program. It won't be an issue 'till you have to learn a non-OOP language.

    Also, most online tutorials are quite condensed so you'll need to use several online resources, and I suggest you get your hands on a book or two. A book will contain much more information and explanation than a simple online tutorial. For example Accelerated C++ by Koenig and Moo is about 350 pages. Teach Yourself C++ In 21 Days, by Jesse Liberty is over 700 pages! (These are both beginning books that essentially cover the same topics as the tutorial.)


    Sticking with ducks....

    In C (a non-OOP language) you can have structures like this:
    DuckDaffy.color
    DuckDonald.age

    But, you cannot have functions "inside" the structure. If you want to change the color or age variable you'll have to write an external function or statement that reaches-in and updates the variable.


    With C++ you can also have functions inside classes (and structures) like this:
    DuckDaffy.IncrementAge()
    DuckDonald.IncrementAge()

    The ability to include functions inside classes allows you to encapsulate functionality.


    With OOP, you can also use inheritance... This allows you to call function like AnimalSound() to make a duck quack or a dog bark:

    DuckDaffy.AnimalSound(); // Quack
    DogSpot.AnimalSound(); // Bark
    Last edited by DougDbug; 11-29-2005 at 02:09 PM.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    34
    ok thanks for the help i would have started whit sometig difrent then c++ but i didn't no about any of the others whine i started i whanted to larn c++ so i wold no how to work this open source game i found=)

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Open Source programs are created for people that know how to program so they can download and change as they wish, they're not really for anyone to download and try to figure out.

    Think of an airplane. It's usually a good idea to learn how to fly before you go off and purchase one rather than buying it and seeing what the instruction manual tells you.
    Sent from my iPadŽ

  7. #7
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    I am also new to object oriented concept (I write programs with C). This summer, i started to learn Java and see that object oriented concept can be fully understood byJava. I recommend you to get a Java tutorial and read it, not for writing the Java code, for learning the basic concepts. The class hierarchy, inheritance, function overload etc...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's a good Object Oriented Strategy for OpenGL/Graphics
    By indigo0086 in forum Game Programming
    Replies: 9
    Last Post: 04-03-2007, 06:27 PM
  2. object oriented C
    By FlatLost in forum C Programming
    Replies: 4
    Last Post: 11-08-2005, 06:22 AM
  3. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM