Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Can someone wxplain classes to me please - the why not wha..

 
   Database Forums (Home) -> PHP RSS
Next:  Why is VARCHAR2(4000) bad ?  
Author Message
colin

External


Since: Jan 21, 2008
Posts: 3



(Msg. 1) Posted: Mon Jan 21, 2008 4:05 pm
Post subject: Can someone wxplain classes to me please - the why not what or how?
Archived from groups: comp>lang>php (more info?)

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.

 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 2) Posted: Mon Jan 21, 2008 4:05 pm
Post subject: Re: Can someone wxplain classes to me please - the why not what or [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

colin.RemoveThis@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.RemoveThis@attglobal.net
==================

 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
Kay

External


Since: Jan 21, 2008
Posts: 2



(Msg. 3) Posted: Mon Jan 21, 2008 4:05 pm
Post subject: Re: Can someone wxplain classes to me please - the why not what or [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.RemoveThis@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.RemoveThis@attglobal.net
> ==================
 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
FFMG

External


Since: Jan 22, 2008
Posts: 1



(Msg. 4) Posted: Tue Jan 22, 2008 12:15 am
Post subject: Re: Can someone wxplain classes to me please - the why not what or how? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 Smile.

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).
 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
Rob

External


Since: Nov 16, 2007
Posts: 14



(Msg. 5) Posted: Tue Jan 22, 2008 5:06 am
Post subject: Re: Can someone wxplain classes to me please - the why not what or [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 21, 6:07 pm, co....TakeThisOut@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.

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.
 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 6) Posted: Tue Jan 22, 2008 8:18 am
Post subject: Re: Can someone wxplain classes to me please - the why not what or [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Rob wrote:
>
> Jerry - what you've described could also be a function as well, not
> that I'm trying to belittle you.
>
<snip>
>
> 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 RemoveThis @attglobal.net
==================
 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
Rik Wasmus

External


Since: Sep 02, 2007
Posts: 210



(Msg. 7) Posted: Tue Jan 22, 2008 11:06 am
Post subject: Re: Can someone wxplain classes to me please - the why not what or how? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 Smile.

*sigh* PHP6 will have namespaces I hear Smile
--
Rik Wasmus
 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
colin

External


Since: Jan 21, 2008
Posts: 3



(Msg. 8) Posted: Tue Jan 22, 2008 2:03 pm
Post subject: Re: Can someone wxplain classes to me please - the why not what or how? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
jstucklex RemoveThis @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
 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 9) Posted: Tue Jan 22, 2008 2:03 pm
Post subject: Re: Can someone wxplain classes to me please - the why not what or [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

colin.DeleteThis@nospmanthanks.com wrote:
> In article ,
> jstucklex.DeleteThis@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.DeleteThis@attglobal.net
==================
 >> Stay informed about: Can someone wxplain classes to me please - the why not wha.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Symbols used in classes. - Hi all., Probably an old quesion, but im pretty new to php, and have not had great success in searching. Ive looking over some code which contains the following terms $this -> :: And have not clue as to what they mean. I have been looking at the ph...

Best way of calling multiple classes? - I'm designing a small framework with a lot of classes (1 file per class) and want to know the best method of calling each class? Obviously I could I call each file that is used but that could be 10 or more include statements. I am wonering if there is...

Plugin system: Automatically instantiate included classes? - Hi there, I am planning to implement a plugin system, based on the observer pattern in some way, but now I am stuck with the instantiation of the plugins. I want the plugins to have their own class, abstracted from the class Plugin. So far its nothing....

json and special chars - Hi! In my DB table I've chars like òèìù but when I generate json file I show \u00e0\u00f2\u00e8\u00ec\u00f9 is it right this change in my char? Thanks

Simple question?? PHP..ODBC..and...dBASE - Ok this may be a dumb question to some but for the first time this evening I have to access dBASE file through ODBC.. I'm trying to do simple queries of SELECT * FROM ??? however I can't for the life of me figure out what to put in place of the ???. Any....
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]