|
|
|
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. |
|
|
Thread Tools |
|
|
#1 |
![]() 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 |
|
|
|
|
|
#2 |
![]() ![]() ![]() ![]() ![]() Member 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. |
|
|
|
|
|
#3 |
![]() ![]() ![]() ![]() ![]() ![]() Member Join Date: Jun 2003
Location: Columbus, Ohio
|
Top-Down: Basic Object Oriented: C# |
|
|
|
|
|
#4 |
![]() 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 |
|
|
|
|
|
#5 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Senior Member 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. |
|
|
|
|
|
#6 |
![]() ![]() ![]() ![]() ![]() ![]() 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 |
|
|
|
|
|
#7 | |
![]() ![]() ![]() ![]() ![]() ![]() Member Join Date: Feb 2001
Location: Flushing Queens NY USA
|
Quote:
__________________
Asus A8N-E Opty 165 2*1gb GSkill DDR-500 Zalman 9500 Cooler Radeon 800XL Seasonic 600 |
|
|
|
|
|
|
#8 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Senior Member 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 signatures!!! Click to read more. I do not endorse any of the products, services or websites in the contextual ads being inserted in my signatures. 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. |
|
|
|
|
|
#9 |
![]() 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 |
|
|
|
|
|
#10 | ||||
![]() ![]() ![]() ![]() ![]() Member Join Date: Oct 2002
Location: Muscle Shoals, AL
|
Quote:
Quote:
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:
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:
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";
|
||||
|
|
|
|
|
#11 |
![]() 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 |
|
|
|
|
|
#12 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Senior Toilet Scrubber 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] |
|
|
|
|
|
#13 |
![]() 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 |
|
|
|
|
|
#14 |
![]() ![]() ![]() ![]() ![]() Member 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. |
|
|
|
|
|
#15 | |
![]() ![]() ![]() ![]() ![]() Member Join Date: Jun 2002
Location: New York City
|
Quote:
![]() 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... |
|
|
|
|
|
|
#16 |
![]() ![]() ![]() ![]() ![]() Member 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. |
|
|
|
|
|
#17 |
![]() ![]() 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 |
|
|
|
|
|
#18 |
![]() ![]() 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 |
|
|
|
|
|
#19 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Senior Member 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;
}
Code:
class base
{
public:
int data;
};
class composed
{
public:
base b;
};
int main()
{
inherited obj;
obj.b.data = 5;
}
|
|
|
|
|
|
#20 |
![]() ![]() Registered Join Date: Aug 2002
|
im using .net..is that any help? |
|
|
|
|
|
#21 | |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Senior Member Join Date: Nov 2003
Location: Michigan, USA
|
Quote:
C++/CLI or Managed C++ C# VB.Net One of the many other .Net/CLI languages I've heard rumour of. |
|
|
|
|
| Thread Tools | |
|
|