Object Oriented Programming is about more than just storing custom data types. It is a whole methodology about thinking of how a real life object behaves. What information makes it up and how can it be used within the application.
It is about storing data in a manner that is protected from other similar collections of data. It does this by providing a set of functions, called methods in object oriented parlance, that allow, and restrict access to the data contained within.
Using Object Oriented Programming transforms the way you write your code so that data is protected, and in many ways writing your code is faster and easier to both write and debug, especially in larger projects
Object Oriented creates some standard practices that make using OO libraries much easier, so we don’t have to write so many utilities ourselves, and the method of writing them is much more consistent.
We generally think of Classes representing something we’d think of as a noun: a person, place, or thing. An Object is a digital reference to that item.
While a person or place is often considered to have a physical representation, a thing may not. Sure, it may be a car, boat, or deck of playing cards, but it’s not guaranteed in programming.
A “thing” can be a bit more abstract. For example, we might have a Data Reader class, which is a way to read data from a file or network stream. It will allow us to open the connection, retrieve data, check to make sure the information isn’t corrupted, etc.
The data stored in our classes help us define what they are. They often describe what makes them unique, for example, an address, or name. However, we will need to work with the data. That is where our methods come into play.
Methods are what functions are called if they belong to an object. Generally, they are things that can be done either to, or by, that object. For example, changing the value of some data, retrieving some data, or performing an operation, such as printing, moving, etc.
public class GamerInfo {
private int accountNumber;
private string gameName;
private int coinCount;
private int level;
public int getLevel() {
return this.level;
}
public void setLevel(int newLevel) {
if(newLevel > 0) {
// some basic error checking to make sure the value is valid
this.level = newLevel;
}
}
public void incrementLevel() {
this.level++;
}
}
Intro to Object Oriented Programming was originally found on Access 2 Learn