What is Object Oriented Programming?
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$5 Answers
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!
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.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$-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-
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$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.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$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!
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.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$