Can someone wxplain classes to me please - the why not what or how?

Can someone wxplain classes to me please - the why not what or how?

am 21.01.2008 19:07:58 von Colin

I understand what a class is but am confused as to why so many people are
using them for what appear to be very simple PHP applications. I guess I
dont know enough about how they are useful.

for example I've just seen a "who is" application thats just 2 files
and a few dozen lines of very simple code

But the author put the thing into a class. This just seems to complicate
the code without providing any benefits as far as I can see.

Can someone explain what the advantage of this is please? And any advice
on when or when not to use classes would be helpful?

cheers

Col.

Re: Can someone wxplain classes to me please - the why not what orhow?

am 21.01.2008 20:42:41 von Jerry Stuckle

colin@nospmanthanks.com wrote:
> I understand what a class is but am confused as to why so many people are
> using them for what appear to be very simple PHP applications. I guess I
> dont know enough about how they are useful.
>
> for example I've just seen a "who is" application thats just 2 files
> and a few dozen lines of very simple code
>
> But the author put the thing into a class. This just seems to complicate
> the code without providing any benefits as far as I can see.
>
> Can someone explain what the advantage of this is please? And any advice
> on when or when not to use classes would be helpful?
>
> cheers
>
> Col.
>

Entire books have been written on Object Oriented Programming. But the
main advantages are to encapsulate the object so you don't have to worry
about details outside of the object (an object is in instantiation of a
class).

For instance - floating point numbers are kept internally as base +
mantissa. To add two floating point numbers, the system has to adjust
one so that the bases are the same, then add the mantissas. Depending
on the result, it may adjust the bases again.

But all of this is transparent to you, the user. The actual operation
is encapsulated.

Properly designed, the code can be reusable. For instance, if I have a
class representing a table in a database. I can put all of the SQL code
in the class, and the rest of the program doesn't have to worry about
the database. I can even change databases or change to a flat file or
XML and all I have to change is the code in the class. Nothing else
needs to be changed.

But this is all very simplistic. I really recommend you visit the
library and check out the books on object oriented programming.



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

Re: Can someone wxplain classes to me please - the why not what or

am 21.01.2008 21:29:56 von kay

Yes, the benefit of using a class to encapsulte the "who is"
functionality, is that anyone can now grab that one class and import
it into their programs.

Its guaranteed not to interfere with anything they have already
created.

Jerry Stuckle wrote:
> colin@nospmanthanks.com wrote:
> > I understand what a class is but am confused as to why so many people are
> > using them for what appear to be very simple PHP applications. I guess I
> > dont know enough about how they are useful.
> >
> > for example I've just seen a "who is" application thats just 2 files
> > and a few dozen lines of very simple code
> >
> > But the author put the thing into a class. This just seems to complicate
> > the code without providing any benefits as far as I can see.
> >
> > Can someone explain what the advantage of this is please? And any advice
> > on when or when not to use classes would be helpful?
> >
> > cheers
> >
> > Col.
> >
>
> Entire books have been written on Object Oriented Programming. But the
> main advantages are to encapsulate the object so you don't have to worry
> about details outside of the object (an object is in instantiation of a
> class).
>
> For instance - floating point numbers are kept internally as base +
> mantissa. To add two floating point numbers, the system has to adjust
> one so that the bases are the same, then add the mantissas. Depending
> on the result, it may adjust the bases again.
>
> But all of this is transparent to you, the user. The actual operation
> is encapsulated.
>
> Properly designed, the code can be reusable. For instance, if I have a
> class representing a table in a database. I can put all of the SQL code
> in the class, and the rest of the program doesn't have to worry about
> the database. I can even change databases or change to a flat file or
> XML and all I have to change is the code in the class. Nothing else
> needs to be changed.
>
> But this is all very simplistic. I really recommend you visit the
> library and check out the books on object oriented programming.
>
>
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================

Re: Can someone wxplain classes to me please - the why not what or how?

am 22.01.2008 06:15:36 von FFMG

Kay;115580 Wrote:
> Yes, the benefit of using a class to encapsulte the "who is"
> functionality, is that anyone can now grab that one class and import
> it into their programs.
>
> Its guaranteed not to interfere with anything they have already
> created.

Unless the name of the class is already used :).

FFMG


--

'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
(http://www.journalhome.com/) | 'webmaster Directory'
(http://www.webhostshunter.com/)
'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
redirection service' (http://urlkick.com/)
------------------------------------------------------------ ------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=24466

Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).

Re: Can someone wxplain classes to me please - the why not what or how?

am 22.01.2008 13:15:48 von luiheidsgoeroe

On Tue, 22 Jan 2008 06:15:36 +0100, FFMG
wrote:

>
> Kay;115580 Wrote:
>> Yes, the benefit of using a class to encapsulte the "who is"
>> functionality, is that anyone can now grab that one class and import
>> it into their programs.
>>
>> Its guaranteed not to interfere with anything they have already
>> created.
>
> Unless the name of the class is already used :).

*sigh* PHP6 will have namespaces I hear :)
--
Rik Wasmus

Re: Can someone wxplain classes to me please - the why not what or

am 22.01.2008 14:06:11 von Rob

On Jan 21, 6:07=A0pm, co...@nospmanthanks.com wrote:
> I understand what a class is but am confused as to why so many people are
> using them for what appear to be very simple PHP applications. I guess I
> dont know enough about how they are useful.
>
> for example I've just seen a "who is" application thats just 2 files
> and a few dozen lines of very simple code
>
> But the author put the thing into a class. This just seems to complicate
> the code without providing any benefits as far as I can see.
>
> Can someone explain what the advantage of this is please? =A0And any advic=
e
> on when or when not to use classes would be helpful?
>
> cheers
>
> Col.

Jerry - what you've described could also be a function as well, not
that I'm trying to belittle you.

This is what I wrote when asked the same question, although it was
actually describing JavaScript classes :-

"A class is just a way of describing what something looks like and how
it works, like a template.

For instance, suppose we had a class called 'Car'. We can create an
'instance' of the class called 'VW Beetle'. Our new copy of 'Car' has
all the things the 'Car' class has, such as wheels, mirrors, doors,
etc - these are called 'Properties' It also has actions, such as
drive, park, reverse, etc - these are called 'Methods'.

We can use the 'Car' template to create as many copies as we want
(using the 'new' keyword). Each copy is known as an 'Object', and
although it has all the features of the class, it is a unique
instance."

In addition to this, one of the most powerful features of a class is
it's inheritance, which you can't do with a function.

Suppose we have a class called 'Vehicle'. We could say it has certain
properties, such as wheels, colour, size, etc. With this base class,
we can also create a whole new class, called 'Car' that inherits all
of the features of the 'Vehicle' class.

We can also add specific 'Car' methods and properties to our new
class, such as engine, ignition, gears, etc. We can also overwrite the
methods of a base class, so instead of the 'ChangeGear()' method of
our Vehicle class effecting just the gears, we could get it to change
the gear and display the current gear on the dashboard.

Obviously Vehicles and Cars is not a real world example, but it gives
you some point of reference about how the models work together, and is
only one good use of classes.

I do agree with you that this can all turn into spaghetti code, but if
used correctly, becomes immensely powerful.

Rob.

Re: Can someone wxplain classes to me please - the why not what or how?

am 22.01.2008 14:18:36 von Jerry Stuckle

Rob wrote:
>
> Jerry - what you've described could also be a function as well, not
> that I'm trying to belittle you.
>

>
> Rob.
>
>

I disagree. Functions have behavior. Objects have both state and
behavior. What I described was an object.

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

Re: Can someone wxplain classes to me please - the why not what or how?

am 22.01.2008 16:32:08 von Colin

In article ,
jstucklex@attglobal.net says...
>
> But this is all very simplistic. I really recommend you visit the
> library and check out the books on object oriented programming.
>
>

Like I said - I understand classes and object oriented programming - it
isnt an issue.

This is what I asked:

for example I've just seen a "who is" application thats just 2 files
and a few dozen lines of very simple code

But the author put the thing into a class. This just seems to complicate
the code without providing any benefits as far as I can see.

To me this appears to be contra-intuative. I'm looking for reasons why
people are doing this as a matter of course with PHP

cheers
Colin

Re: Can someone wxplain classes to me please - the why not what orhow?

am 22.01.2008 20:01:36 von Jerry Stuckle

colin@nospmanthanks.com wrote:
> In article ,
> jstucklex@attglobal.net says...
>> But this is all very simplistic. I really recommend you visit the
>> library and check out the books on object oriented programming.
>>
>>
>
> Like I said - I understand classes and object oriented programming - it
> isnt an issue.
>
> This is what I asked:
>
> for example I've just seen a "who is" application thats just 2 files
> and a few dozen lines of very simple code
>
> But the author put the thing into a class. This just seems to complicate
> the code without providing any benefits as far as I can see.
>
> To me this appears to be contra-intuative. I'm looking for reasons why
> people are doing this as a matter of course with PHP
>
> cheers
> Colin
>
>

Well, as Kay said - it encapsulates the functionality, making it easier
to do a "whois" on other pages - either for this site or another.

It also means if you need to change the code, you only need to change it
in one place and it won't affect the rest of your code.

I'm always looking for ways to encapsulate things. I don't do
everything, but I do a lot.

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