Kreij
Senior Monkey Moderator
- Joined
- Feb 6, 2007
- Messages
- 13,817 (2.21/day)
- Location
- Cheeseland (Wisconsin, USA)
The Official OOP Guide for Rednecks ™ * ** ***
(* I'm a northern redneck. If you take offense at the term KMA)
(** this guide assumes you know at least a little about programming, like what a variable is)
(*** TPU, all it's affiliates and especially Kreij take no responsibility for anything)
Object Oriented Programming (OOP) has been around for quite some time and this guide is meant to try to make it as easy as possible to understand the terms and ideas associated with it. No more, no less. So grab yourself a beer and we'll get started.
What is OOP?
OOP is a paradigm or programming methodology. WUT?
It's just a way of looking at programming. OOP programming looks at the program from the standpoint of … you guessed it … objects.
That beer in your hand? That's an object.
The fact that's it's almost empty now? That's not an object. Go get another.
We'll get to all that shortly.
What is the history of OOP?
Google it, this is a guide, not a history lesson.
They say that those that forget history are destined to repeat it. I say grab another beer. You're call.
When should I use OOP?
When your program requires the use of objects. Duh.
What's an object?
Anything that has a state (one or more properties) AND a need for some way to manage a change of those states. WUT?
As I said, that beer is an object. One of it's properties might be “Amount left”, which will change over time. The program may have a function (or method as they are usually called) named “Get Another Beer”, based on the “Amount Left” property.
How do I make an object?
It's really easy. You just create a class that defines the object, it's properties and state management methods. WUT?
Okay, let's look at some code (all examples are in C# 'cause it's easy to understand what you are looking at).
Coming Soon … What to do with the class you just made and an explanation of everything in it. I'll append it to this post.
(Give me a break, these guides take a lot of time to write, proofread and get right. )
Comments always appreciated.
(* I'm a northern redneck. If you take offense at the term KMA)
(** this guide assumes you know at least a little about programming, like what a variable is)
(*** TPU, all it's affiliates and especially Kreij take no responsibility for anything)
Object Oriented Programming (OOP) has been around for quite some time and this guide is meant to try to make it as easy as possible to understand the terms and ideas associated with it. No more, no less. So grab yourself a beer and we'll get started.
What is OOP?
OOP is a paradigm or programming methodology. WUT?
It's just a way of looking at programming. OOP programming looks at the program from the standpoint of … you guessed it … objects.
That beer in your hand? That's an object.
The fact that's it's almost empty now? That's not an object. Go get another.
We'll get to all that shortly.
What is the history of OOP?
Google it, this is a guide, not a history lesson.
They say that those that forget history are destined to repeat it. I say grab another beer. You're call.
When should I use OOP?
When your program requires the use of objects. Duh.
What's an object?
Anything that has a state (one or more properties) AND a need for some way to manage a change of those states. WUT?
As I said, that beer is an object. One of it's properties might be “Amount left”, which will change over time. The program may have a function (or method as they are usually called) named “Get Another Beer”, based on the “Amount Left” property.
How do I make an object?
It's really easy. You just create a class that defines the object, it's properties and state management methods. WUT?
Okay, let's look at some code (all examples are in C# 'cause it's easy to understand what you are looking at).
Code:
[color=Blue]public class[/color] Beer
{
[color=Blue]private[/color] [color=Teal]Int32[/color] _AmountLeft = 100;
[color=Green]// This makes the beer full when you create it.[/color]
[color=Blue]private[/color] [color=Teal]Boolean[/color] _GetAnotherBeer = [color=Blue]false[/color];
[color=Green]// This is true or false, depending on how much beer is left.
// We set it to false originally because the beer is full when you open it[/color]
[color=Blue]public[/color] Beer() {};
[color=Blue]public[/color] [color=Teal]Boolean[/color] GetAnotherBeer { [color=Blue]get[/color] { [color=Blue]return[/color] _GetAnotherBeer; } }
[color=Blue]public void[/color] TakeAnotherGulp()
{
_AmountLeft = _AmountLeft – 20; [color=Green]// Subtract 20% of the beer each gulp.[/color]
if (_AmountLeft < 40) _GetAnotherBeer = [color=Blue]true[/color];
[color=Green]// If your down to your last gulp, set GetAnotherBeer to true[/color]
}
}
Coming Soon … What to do with the class you just made and an explanation of everything in it. I'll append it to this post.
(Give me a break, these guides take a lot of time to write, proofread and get right. )
Comments always appreciated.