Ask questions via twitter! Message any question to @answers on twitter. We'll publish the question and send you a reply each time there's a new answer.
Next Question

Answered Question

 
 M¢25  Funded By Mahalo ? |  November 05, 2009 11:30 AM

What is Object Oriented Programming?

Interesting Question?  Yes (0)   No (0)   
RSS
 
 

Best Answer  Decided by Votes

 
November 05, 2009 03:55 PM
Since the other two answerer have given definitions, I'll try to give you a realistic example to make it a little more understandable (and hopefully it makes sense)
Object oriented programming does treat things as objects which can possess traits and properties (the fields) and perform or be affected by an action (the methods).
Say your using object oriented programming to handle the front end side of a program which stores customer data. It would most likely store the data on the back side in some sort of database.
Every time you have a customer, you need to create a new customer. The class is like a factory, so you most likely will have a customer class. The customer class will contain constructors, which define what properties each object has. You can just have 1 constructor, but usually there are a series of them, and which one is created depends on which parameters you pass in. So something like (in java.. sorry if my syntax is inconsistent, I've been programming a lot of different languages lately.)

Customer cust1 = new Customer();

That gives you a customer object, with the name cust1. It would also call the default constructor because the parenthesis are blank (not passing in any info to the constructor), so whatever the Constructor gives it is what it has. This could be nothing (just a blank customer) or it could have things like

string birthDate;
string address;
string phoneNumber
int numOfPurchases

Which are most likely initialized to NULL. It's just saying that the customer HAS a birth date (but the birth date hasn't been determined), the customer HAS an address (which isn't determined), and etc. your numOfPurchases will almost always be set to 0, since a new customer won't have made any purchases yet.
You may then have another constructor that takes in that information, so maybe your call is
:
Customer cust2 = new Customer("Feb 20th 1975", "123 Maple Street", "555-5555")

The number of purchases might be set from within the constructor since it's going to be the same for every customer.
Realistically, that information would be pulled out of a form or other user input rather than hard coded.
So cust2 now HAS a birth date, and it's been defined as Feb 20th 1975, they HAVE a phone number, which is 555-555, and etc.
So birth date, address, and phone number, and number of purchases are the properties which each employee has. You can change one of the properties without changing the whole employee, like

cust2.PhoneNumber = "519-2345";

which is going to set the phone number property of cust2 to 519-2345.

Because each of these properties is like a trait of an object, if the object is deleted, it's properties are too. So if you delete cust2 out of the system, it's phone number, birth date, and address disappear too unless you copy that information elsewhere first - but it's not really useful without the object. The number of purchases is the only one that may want to be kept, just for sales statistics.

Then there are methods which can affect each object. So in the case of a customer, you might have something like updating the fields (which is likely most common).

Each time a purchase is made, you want to increase the number of purchases by one. Think of methods as actions, and often, each one is named with a verb.
So you'd have something like:

public int buySomething()
{
numOfPurchases = numOfPurchases + 1;
return numOfPurchases;
}

Of course, it would likely have much more code, since it is called when you buy something, like you might want to calculate costs from here or get more information or whatever. In this case, you are passing nothing in and returning an int representing the new number of purchases

Then, you call that method with your customer, so:

int purchases = cust1.buySomething()

This would buySomething with cust1, and since it is returning an integer, your saving that integer to the variable purchases, which could then be used for something like displaying the number of purchases on the screen. You could also have no return, and then you'd just assume that it worked.

Does that give you the start of an idea about what OOP is, or do you want me to explain anything else?

Wikipedia does a fairly good job of explaining the concepts so you might want to check that out here

Good luck!
Source(s):
3rd year programming student that has taken -
Java
C++
C#
Visual Basic
SQL
HTML & CSS
and way too many more that I can't keep them all straight.



Tags: oriented, programming, object, java, oop

Helpful Answer?  (0)   (0)    Tip girlieq3000 for this answer
Permalink | Report
Voted as best: docbrown, eskay, safiqulislam
   Reply  
 
 

Other Answers (4)

Sort By
 
November 05, 2009 11:49 AM
Object-oriented programming is a programming paradigm that uses objects to design applications and computer programs. Programming techniques may include features such as information hiding, data abstraction, encapsulation, modularity, polymorphism, and inheritance.

Helpful Answer?  (0)   (0)    Tip smartassmissy for this answer
Permalink | Report
Voted as best: theenlightened
   Reply  
 
 
 
November 05, 2009 12:14 PM
It's a programming language that focuses more on objects rather than actions.

-quote-

"Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.

The programming challenge was seen as how to write the logic, not how to define the data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them. Examples of objects range from human beings (described by name, address, and so forth) to buildings and floors (whose properties can be described and managed) down to the little widgets on your computer desktop (such as buttons and scroll bars)."

-end of quote-
Source(s):
http://searchsoa.techtarget.com/sDefinition/0,,sid26_gci212681,00.html


Helpful Answer?  (0)   (0)    Tip edwardclint for this answer
Permalink | Report
Voted as best: kaliekat
   Reply  
 
 
 
November 06, 2009 01:28 AM
Object-Oriented Programming is the use of objects to design and organize your code. OO code is easier to reuse and extend and often simplifies difficult problems by allowing them to be broken up into natural parts.

The basic, key improvement that OOP provides is the ability to maintain state. Without objects, any data you want a function to have access to must be passed in as a parameter or be global. With object-oriented programming, each object maintains information about itself, so that any time a method is called on an object, the object's information influences the behavior of the method.

More advanced OOP allows relationships between objects, whether an object has another object (e.g. a student has a name), uses another object (a student uses a library book), or is a type of another object (a student is a person). OOP promotes good design and code re-usability.

Helpful Answer?  (0)   (0)    Tip srgothard for this answer
Permalink | Report
   Reply  
 
 
 
November 06, 2009 09:32 AM
In classic, procedural programming you try to make the real world problem you're attempting to solve fit a few, predetermined data types: integers, floats, Strings, and arrays perhaps. In object oriented programming you create a model for a real world system. Classes are programmer-defined types that model the parts of the system.

A class is a programmer defined type that serves as a blueprint for instances of the class. You can still have ints, floats, Strings, and arrays; but you can also have cars, motorcycles, people, buildings, clouds, dogs, angles, students, courses, bank accounts, and any other type that's important to your problem.

Classes specify the data and behavior possessed both by themselves and by the objects built from them. A class has two parts: the fields and the methods. Fields describe what the class is. Methods describe what the class does.

Using the blueprint provided by a class, you can create any number of objects, each of which is called an instance of the class. Different objects of the same class have the same fields and methods, but the values of the fields will in general differ. For example, all people have eye color; but the color of each person's eyes can be different from others.

On the other hand, objects have the same methods as all other objects in the class except in so far as the methods depend on the value of the fields and arguments to the method.

This dichotomy is reflected in the runtime form of objects. Every object has a separate block of memory to store its fields, but the bytes in the methods are shared between all objects in a class.
Source(s):
http://www.examville.com


Helpful Answer?  (0)   (0)    Tip farlow for this answer
Permalink | Report
Voted as best: kareul
   Reply  
 
 
 
November 06, 2009 11:30 AM
Hey, and welcome to Mahalo!
Just wanted to mention that you should attempt to avoid copy and pasting whenever you can. Try to put things in your own words, and summarize. Try reading Copy and Pasting on Mahalo for some more information.
Good luck!

Report
 
 
Buy Mahalo Dollars with Credit Card or PayPal

Top Members

This Week All Time
  • buddawiggi
    buddawiggi
    2nd Degree Black Belt
    27543 Points
    M$789.91 Earned
  • opher
    opher
    Purple Belt
    4443 Points
    M$196.22 Earned
  • annelisle
    annelisle
    Purple Belt
    2997 Points
    M$91.22 Earned
   See All
 

Most Popular Tags

mahalo(1614)
iphone(465)
music(459)
google(357)
food(321)
online(295)
beer(279)
money(262)
movies(255)
apple(251)
aotd(235)
health(219)
video(207)
dog(205)
free(204)
   See All
 

Categories

Welcome New Members


 
 
Mahalo Dollars are the currency of Mahalo Answers.

Each Mahalo Dollar costs $1.

Once you earn more than 40 Mahalo Dollars, you can request to be paid via PayPal. Each Mahalo Dollar is currently worth $0.75 when paid out via PayPal. Learn More

 
 

Please log in to use this function.