Overclockers Forums
 


Go Back   Overclockers Forums > Software > Programming Tips and Tricks > Object Oriented Programming
Reply


Welcome to the Overclockers Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

If you would prefer not to see any double-underlined words and corresponding advertisements without registering or logging in, place your cursor
here for ContentLink
 
Thread Tools
Old 04-09-05, 11:29 PM   #1
Solo3021
Registered



Join Date: Jul 2004
 
Object Oriented Programming

I was hoping that maybe someone could help explain to me the difference between Object Oriented Programming (OOP) and Top-Down Programming, and maybe list some examples.

__________________
"Never tell me the odds." - Han Solo, The Empire Strikes Back
Solo3021 is offline   Reply With Quote
Old 04-10-05, 12:18 AM   #2
grimm003
Member

 
grimm003's Avatar 

Join Date: Jul 2004
Location: SIU
 
Well I'm taking some Java classes in school so I can explain a little about Object Ori. In Java you need to creat objects in order to do any methods to change something or access it. For a basic example, a String in java is an object. So first you create the object, and then you can use it's methods on that object(like get its length, find a character, make a substring, etc.). You can write your own classes to make any sort of object you need, and then you can write your own methods to access or mutate it however desired.
Hope this helps, java is my 1st programming language and it is pretty easy btw.

__________________
Motherboard ASUS P5Q Deluxe
CPU E8400
RAM Mushkin DDR2-1000 2x2GB
Video Sapphire HD4870 512MB
Case Lian-Li A-7010
Res MCR320-QP
CPU Block GTZ
Video Block MCW60-R2
Pump MCP355

There are 10 kinds of people in the world.
Those that understand binary, and those that don't.
grimm003 is offline   Reply With Quote
Old 04-10-05, 12:40 AM   #3
Chris_F
Member

 
Chris_F's Avatar 

Join Date: Jun 2003
Location: United States
 
Top-Down: Basic
Object Oriented: C#
Chris_F is offline   Reply With Quote
Old 04-10-05, 12:40 AM   #4
Solo3021
Registered



Join Date: Jul 2004
 
yeah, I'm taking a VB.NET and C++ course right now.

So the main theory behind OOP is that you Define objects (re-usable code) and make copies with different classes?

__________________
"Never tell me the odds." - Han Solo, The Empire Strikes Back
Solo3021 is offline   Reply With Quote
Old 04-12-05, 08:47 AM   #5
mccoyn
Senior Member

 
mccoyn's Avatar 

Join Date: Nov 2003
Location: Michigan, USA
 
With object oriented programming you abstract ideas and things as objects. Objects can store data and implement functions. In object oriented programming you design interfaces to objects and functionality within objects.

With procedural programming you write a series of steps to complete a task. The major difference is you don't abstract ideas into objects, you just store all the necessary information and use it as needed. This is a much more direct approach, but can be very confusing if you have a lot of items to deal with, such as designing user interfaces.

Top down programming isn't very comparable to object oriented programming. Its more of a method used to develop programs and can be used with either object oriented programming. Top down refers to a method of designing a program; First, you thing about the most general level of the program. Once you design that level you look at all the pieces you will need to implement it, then you desing those. After that you will need even more pieces so you design those. This repeats until all the pieces are designed. Basically, you start from the most general (top) and work your way to the most specific (bottom.) This can apply to design or implementation, but it is almost always used for design, after all how can you know what small pieces you need if you don't know the main flow.

Bottom up programming is the opposite; You move from the most specific (bottom) and work your way to the most general (top.) This is sometimes used for implementation. You focus on implementing the small pieces and then integrate them into the bigger ones.

All of these concepts can be mixed. Object oriented programs usally depend on small blocks of procedural code in their implementation. Object oriented concepts can even be implemented in a purly procedural language like C. During a design you might work top down, but then realize that some low level functionality needs to be present in the high level design so you will work bottom up to fix it.

Whats the difference between object oriented programming and top down programming? Object oriented programming is a code organization strategy and top down programming is a design strategy. When a program has been writed it is usally very easy to tell if it was object oriented or not by looking at the code organization. Top down, however, usally can't be determined by looking at the code.
mccoyn is offline   Reply With Quote
Old 04-12-05, 11:57 AM   #6
Tacoman667
Member



Join Date: Apr 2001
Location: Kingwood, TX
 
Also, when you use object-oriented code, you are basically making a class that you would need to define once. Then you will make all objects according to that class. It uses alot less code, is VERY adaptable to other programs written laster on, and is pleasing to the eye. It is so much easier looking, reading, and understanding my C++ code for student's grades using objects then it is to look at my BASIC code with procedures and subroutines.

I like object-oriented alot better because of the ability to use those classes anywhere I want.

__________________
Who was the first person to look at a cow and say, "I think I'll squeeze these dangly things here, and drink whatever comes out?"

Who was the first person to say "See that chicken there....I'm gonna eat the next thing that comes out of it's butt."



A64 3200+
DFI LanParty UT NF3 250GB
1024meg 2x512meg Kingston HyperX
ATI 9800 PRO 128meg
2x80gig Maxtor SATA RAID0
Tacoman667 is offline   Reply With Quote
Old 04-13-05, 02:24 PM   #7
dgk
Member



Join Date: Feb 2001
Location: Flushing Queens NY USA
 
Quote:
Originally Posted by Chris_F
Top-Down: Basic
Object Oriented: C#
What version of Basic would that be? Nothing since QuickBasic fits that description. Everything since then is event driven.

__________________
Asus A8N-E Opty 165
2*1gb GSkill DDR-500
Zalman 9500 Cooler
Radeon 800XL
Seasonic 600
dgk is offline   Reply With Quote
Old 04-14-05, 12:57 AM   #8
MRD
Senior Member

 
MRD's Avatar 

Join Date: Feb 2003
Location: CT
 
A better comparison would be C versus C++. Let's stick to clear, standard languages. Basic is all over the place, and C# is really just a gimmicky Microsoft thing, not really it's own language, but more of a spinoff because Microsoft was ****ed off that someone else was defining computer industry standards.

C is a truly procedural language. You can do a few object oriented type things in it, but it's hard and doesn't really work well, and it's generally not supported by the language.

C++ is completely object oriented. The main thing that makes it so is the existence of classes. For example, if you have a string of text you want to get from the user and print, in C, you create an array in memory, then go ask the user for the text, write it to memory, then call another function that reads that memory and prints it out. If you do the same in C++, you create a string object, then tell the string object to use its member function to go get info from the user and change itself to have that information associated with it. Then you tell the string object to go print itself using a member function that knows how to output the information held in the string. In the procedural case, you had to know how the information was stored to print it out. In the object oriented case, you don't care, you just tell it to print itself, and the rest is handled by the class.

Object oriented programming is a newer idea, and is a higher level of abstraction. This is why it is more popular and is replacing procedural programming as the main programming method used for software development for the PC. Procedural programming is mostly now used when you need extremely high speed or extremely low memory usage, such as programming the firmware in your microwave or television.

__________________
I do not support inline advertising in my posts!!! Click to read more.
I do not endorse any of the products, services or websites in the contextual ads being inserted in my posts. I urge you to refuse to support any company that uses these ads, and to use Mozilla Firefox and Adblock Plus (both freely available from the Firefox homepage) to block all such ads.
The decision to include inline ads was made by iNet in
direct violation of previous promises to the contrary, not by the administrators, moderators or other dedicated, volunteer forum staff who have always worked hard to maintain the integrity of the website and ensure a positive user experience.
MRD is offline   Reply With Quote
Old 04-14-05, 06:21 PM   #9
Solo3021
Registered



Join Date: Jul 2004
 
Ok, these might be C++ only questions, then again, I'm still learning and they might apply for more than just C++.

I don't know the difference between a function and a member function, can someone explain to me the difference?

Can someone explain to me the difference between classes and objects... I'm afraid I might be getting the terminology mixed up.

And in C++, I've seen instances of things seperated by dots, (ex. body.size). What is this, and how does it work?

__________________
"Never tell me the odds." - Han Solo, The Empire Strikes Back
Solo3021 is offline   Reply With Quote
Old 04-14-05, 08:34 PM   #10
TheGame240
Member

 
TheGame240's Avatar 

Join Date: Oct 2002
Location: Muscle Shoals, AL
 
Quote:
Originally Posted by Solo3021
Ok, these might be C++ only questions, then again, I'm still learning and they might apply for more than just C++.
Most concepts are language independent, while operators, syntax, etc. is language dependent.

Quote:
Originally Posted by Solo3021
I don't know the difference between a function and a member function, can someone explain to me the difference?
A function, in general, is a stand along rountine. For example, if below the main you write a routine to format and print text from a file and include it in a function PrintFile().

A member function is a function which is part of a class. Much of the difference has to do with the scope (area where a program element may be used) of the function. A member function declared within a class is used only with instances of that class. Depending on the function declaration (public or private) you may only be able to call a function from within other functions of the class.

Quote:
Originally Posted by Solo3021
Can someone explain to me the difference between classes and objects... I'm afraid I might be getting the terminology mixed up.
A class is a collection of data and associated operations on the data. For example take a bank account. A bank account class would need data members: Name, account number, balance, last statement date, etc. The operations you would need on the account (member functions) would be deposits, withdraws, calculate interest, print a statement, etc.

When you declare an instance of a class, the instance is an object.
For example when you declare a file stream variable

ifstream InFile;

InFile is an instance (object) of the ifstream class.

Quote:
Originally Posted by Solo3021
And in C++, I've seen instances of things seperated by dots, (ex. body.size). What is this, and how does it work?
The dot operator is used to call member functions or to reference member data objects. It works the same for structs, classes, etc. For example.

Code:
struct UserStruct
{
     string name, address, age;
};

//Declare and instance of the UserStruct type
UserStruct TheObjectUser;

//To reference the address of TheObjectUser use the dot operator
TheObjectUser.name = "some name";
TheGame240 is offline   Reply With Quote
Old 04-14-05, 10:38 PM   #11
Solo3021
Registered



Join Date: Jul 2004
 
Well, I really must thank you all for your help, but TheGame240's help proved exceptionally valuable. So much of what I have learned about programming clicked with that explanation. As if most everything makes sense now. I thank you all for your help.

And I luckily learned structures just last night. Thank you again for helping to explain the theory and terminology of OOP.

__________________
"Never tell me the odds." - Han Solo, The Empire Strikes Back
Solo3021 is offline   Reply With Quote
Old 04-14-05, 11:16 PM   #12
Ebola
Senior Toilet Scrubber

 
Ebola's Avatar 

Join Date: Jan 2001
Location: Rosemount, MN
 
I'm surprised no one defined oop as inheritance, polymorphism, and encapsulation. I'm just a newbie trying to cram info so I'm not about to give my poor definitions.

__________________
[Cythraul Design]
Ebola is offline   Reply With Quote
Old 04-16-05, 11:24 PM   #13
Solo3021
Registered



Join Date: Jul 2004
 
I understand inheritance, but for the other two... I could make guesses, but I really don't know.

__________________
"Never tell me the odds." - Han Solo, The Empire Strikes Back
Solo3021 is offline   Reply With Quote
Old 04-21-05, 09:38 PM   #14
grimm003
Member

 
grimm003's Avatar 

Join Date: Jul 2004
Location: SIU
 
well I can take a stab, just for those curious. Encapsulation refers the the visibility of inheritance. Each parent class should have it's own variables that are private to its child class directly, but can be accessed indirectly by using methods. From what I understand it is just to make sure that no child class can change variables from the parent class, but can use them and make copies if needed.
Polymorphism, just started learning about it, but in general it's treating one reference name/object as different kinds of objects in a program at different times.

__________________
Motherboard ASUS P5Q Deluxe
CPU E8400
RAM Mushkin DDR2-1000 2x2GB
Video Sapphire HD4870 512MB
Case Lian-Li A-7010
Res MCR320-QP
CPU Block GTZ
Video Block MCW60-R2
Pump MCP355

There are 10 kinds of people in the world.
Those that understand binary, and those that don't.
grimm003 is offline   Reply With Quote
Old 04-22-05, 01:45 AM   #15
fatguy
Member

 
fatguy's Avatar 

Join Date: Jun 2002
Location: New York City
 
Quote:
Originally Posted by Ebola
I'm surprised no one defined oop as inheritance, polymorphism, and encapsulation. I'm just a newbie trying to cram info so I'm not about to give my poor definitions.
Don't forget Abstraction

Your best bet is to pick up a basic OO book, or simply google for Object Oriented Basics. While we could help answer individual questions, it's not enough to get a true understanding of the beauty of OO...

__________________



HEATWARE
fatguy is offline   Reply With Quote
Old 04-24-05, 02:32 PM   #16
grimm003
Member

 
grimm003's Avatar 

Join Date: Jul 2004
Location: SIU
 
this is a great link I found. Many free programming books online

__________________
Motherboard ASUS P5Q Deluxe
CPU E8400
RAM Mushkin DDR2-1000 2x2GB
Video Sapphire HD4870 512MB
Case Lian-Li A-7010
Res MCR320-QP
CPU Block GTZ
Video Block MCW60-R2
Pump MCP355

There are 10 kinds of people in the world.
Those that understand binary, and those that don't.
grimm003 is offline   Reply With Quote
Old 04-25-05, 02:40 AM   #17
ndnsoulja
Registered



Join Date: Aug 2002
 
i came to the site with similar questions about oop, and saw this thread and thought, why not put my question here. some of my questions are answerred already from reading this thread but what is composition? my teacher wants us to do a program in composition and then do it in inheritance. i don't really understand the two. can someone help me out with that one? thank alot
ndnsoulja is offline   Reply With Quote
Old 04-25-05, 03:48 AM   #18
ndnsoulja
Registered



Join Date: Aug 2002
 
an exple would be a real big help. if someone can post like an example of composition and one of inheritance and then explain the difference that would be highly appreciated. thank you
ndnsoulja is offline   Reply With Quote
Old 04-25-05, 09:36 AM   #19
mccoyn
Senior Member

 
mccoyn's Avatar 

Join Date: Nov 2003
Location: Michigan, USA
 
Composition isn't really a standard term so I'm not sure what he is talking about. What language are you using, that could be a clue.

Inheritance is when one class is derived from another and inherits its methods and data structure.

Code:
class base
{
public:
  int data;
};

class inherited : public base
{
};

int main()
{
  inherited obj;
  obj.data = 5;
}
My best guess on composition is that it uses a member variable to store another class.
Code:
class base
{
public:
  int data;
};

class composed
{
public:
  base b;
};

int main()
{
  inherited obj;
  obj.b.data = 5;
}
mccoyn is offline   Reply With Quote
Old 04-27-05, 02:52 AM   #20
ndnsoulja
Registered



Join Date: Aug 2002
 
im using .net..is that any help?
ndnsoulja is offline   Reply With Quote
Old 04-27-05, 04:08 PM   #21
mccoyn
Senior Member

 
mccoyn's Avatar 

Join Date: Nov 2003
Location: Michigan, USA
 
Quote:
Originally Posted by ndnsoulja
im using .net..is that any help?
Dotnet is a library available in many languages. It helps a little, but isn't what I was after. You are probally using one of the following languages; Which is it?

C++/CLI or Managed C++
C#
VB.Net
One of the many other .Net/CLI languages I've heard rumour of.
mccoyn is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:50 PM.


Top of PageLast Page

Home  |   Register  |   Calendar  |   FAQ  |   Search  |   Contact Us  |   Archive
Copyright © OCForums.com 2001 - 2008. All Rights Reserved.    Visit: Overclockers.com.    Advertise on OCForums


Other iNET Interactive Sites:
Web Hosting Talk | DB Forums | Mac-Forums | Hosting Catalog | Hot Scripts
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.