I am kind of a slow learner I guess when it comes to coding, I have been learning PHP for a couple of years and I still don’t understand Classes so it’s time I put some effort in to at least understanding them a little better.
I use functions for everything. People often make comments to me on here that they can’t believe I have a social network site and I don’t use classes.
I really do not understand the benefit of them can you explain the benefits besides it supposedly being easiar for multiple people to work on your code?
To me it seems like classes just complicate simple task
Simply (in fact, extremely simply), classes allow you to organize code in logical units as well as provide containers and templates for user-created objects.
Let’s say you have a car… A car can has a capacity and people inside.
Now, we can start using those cars:
I now have 2 cars (instances), which holds different data.
I might also want to have a van, which will have an additional property for doors:
Now let’s use that van:
Now maybe you can see how we could apply those concepts towards the creation of, for example, a
DBTableand aUserclass.In fact, it’s hard to really start explaining why classes simplify one’s life without getting into the concepts of Object Oriented Programming (abstraction, encapsulation, inheritance, polymorphism).
I recommend you read the following book. It will help you grasp the core concepts of OOP and help you understand why objects to really make your life easier. Without an understanding of those concepts, it’s easy to dismiss classes as just another complication.
PHP 5 Objects, Patterns, and Practice
PHP 5 Objects, Patterns, and Practice http://ecx.images-amazon.com/images/I/51BF7MF03NL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA240_SH20_OU01_.jpg
Available at Amazon.com