You are here: Re: Classes, don't follow. « PHP Programming Language « IT news, forums, messages
Re: Classes, don't follow.

Posted by Jerry Stuckle on 10/11/05 14:44

Jace Benson wrote:
> Well... I am trying to understand here. Before I start, thanks for all
> the information you've given me.
>
> So please correct me if I am wrong.
>
> Classes are a container.. if you will something to put what a <thing>
> does.
> if for instance I was making a program on a pet. I would want to label
> it Class Pet {...}
> (dont be so tight on the gramatical errors, I am just trying to figure
> this out).. Anyways In the class Pet I would put in it the
> methods?(these are also the functions)? that the pet would do. So say
> I wanted to call the class pet and make a new instance of a dog and i
> wanted that dog to poop.
> Would this be how i should look at that in OO programming?
> //make this class
> //classes dont create things methods do
> Class Pet {
> var $pets_name;
> function ChooseAPet() {
> //some function pulling data from an array printing
> //it to a form to select it and send it back with a name
> }
> }
> Class Action {
> var $action;
> function Action(){
> //this will be called whenever the class is caled
> //some thing like before but pulling data for what an animal can
> do.
> }
> function Stop(){
> //something to stop an action for instance
> //a pet might take a long time to sleep but not long to jump
> }
> function Create(){
> //when some actions happen things are created like stools
> }
> }
>
> not the best example but this would be a valid theroized Class
> design..?
>
> I feel like i dont' get it. I under stand to seperate is good, but I
> am lost.
>

Hi, Jace,

Samuel has given you an excellent example. I'll try another (in a sec.).

The whole idea of object oriented programming is to bring "real world"
objects into the "programming world". That is, to create something in
the programming world which mimics what we're already familiar with.

If you had a real world pet, would you think of it as performing
"Action", "Stop" and "Create"? Or would you think of it as performing
"Bark", "Eat", "Sit", "Poop"?

The other example I've used in a lot of classes - an automobile. Take
some basic actions - start, stop, change gear, accelerate and stop.

The car itself keeps track of basic things like its running status, the
gear it's in, its speed, and how much gas is in the tank.

When you "start" the car, some things must be in place. The car must
not already be started, there must be gas in the tank and the gear must
be in park or neutral (assuming an automatic transmission).

To accelerate, the engine must be running, the brake off and the
transmission in gear.

The beauty here is - you, as a user of the car class, don't have to
worry about testing the various states - the car class will do it for
you (for instance - lets say you add a new status "Battery Charged").
You change the "Start" method to test for this - but don't need to
change anything else in your program.

OO programming is a completely different way of thinking. Interestingly
enough, in my classes I've found the people with the least programming
experience typically have the least trouble making the switch. Those
with lots of programming experience have the most trouble. It's quite
difficult to "unlearn" years of learning!


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация