dole_doug — 2010-12-05T13:35:47-05:00 — #1
I wish to learn OO PHP and cakephp framework.At this stage i don;t have a good understanding of OO conceptual thinking.
1)Can you help me with some simple samples with tutorials.
2)Can you give me with some simple classes and things related to OO in order to help a beginner to understand this field.
3)Do you know a site which has problems and solutions to the problems?
4)Do you have any advice?
ernie1 — 2010-12-05T14:26:56-05:00 — #2
I recommend a few books:
Head First Java, Second Edition
By Kathy Sierra, Bert Bates
Patterns of Enterprise Application Architecture
By Martin Fowler, David Rice, Matthew Foemmel, Edward Hieatt, Robert Mee, Randy Stafford
PHP Objects, Patterns, and Practice, Second Edition
By Matt Zandstra
PHP 5 OOP By: Ilia Alshanetsky
jream — 2010-12-05T14:50:55-05:00 — #3
I second this book!! : PHP Objects, Patterns, and Practice
That's a very good book! It gets harder and harder so you'll be reading it a while but it gets you started pretty good in the first chapters.
The hardest part is that you have to change your thinking. It's kind of like thinking in terms of drawing pictures and connecting things together in your mind, rather than thinking of a script running top to bottom.
And you could get a Java Book too because the same prinicpals apply (Since the guy above mentioned a Java book).
The Lingo is confusing at first
A Class just a template for an object. When you create an object with something like $object = new Class(); , you are creating an Object (an Instance) based on the Class Template.
So a class doesn't go beyond defining rules for your Object to drive on, kind of like railroad-tracks, and your object is the train.
A good order to learn the basics in:
1 - How to write a simple Class
2 - Methods (They are the same thing as functions, but called methods inside an Object)
3 - Properties (They are the same thing as variables, but called properties inside an Object)
4 - How to create a new object with your class
5 - Learn how to use this $this keyword.
6 - If you are feeling really adventurous look into Extending classes, this part will take time to get used to though, but this is a good order to start in!
Some keywords to memorize: Class, Method, Property, New, $this, Extends
mangiaphoto — 2010-12-05T16:15:36-05:00 — #4
PHP Objects, Patterns, and Practice is a great book.
If you can, search for a third edition. It is released a few months ago.
alle — 2010-12-05T16:19:46-05:00 — #5
I can give a few somewhat sporadic but I think well founded thoughts for those introducing themselves to object oriented methodology.
Objects represent anything that is generally shared between instances of the application execution, or multiple times within it, but where the instances have something that sets them apart between each other. If all object instances are the same, it is not necessary to have a class, though you may use what I would call a "pseudo class" with static properties, which are really the same for all instances and thus not truly to be thought of as a class of objects.
Objects can be used to compartmentalise your applications, if there are several variants or extensions of object classes, consider extending them. The comparmentalisation makes it possible to have a main outline of the application where different functionality is encapsulated in the different objects. This is very useful when working in a team, since it is sufficient to have this shared outline and interfaces, to be able to distribute work on different objects to different people.
A good practice for a beginner would be to use objects for pages, and then extend their classes for other page variants. That gives practical experience in how you can make use of objects to share and compartmentalise implementation.
You will soon find that some objects are separate from pages, suppose that you have a marketing application or at least marketing functionality and some kind of cart. The cart is a separate kind of object from the application's pages. So you'd reasonably create a separate cart class. The cart may be made a separate compartment of your program, for example a separate file which you simply include. It needs certain functionality; add, remove, update. This translates into the properties which a cart object has.
The more and clearer your underlying understanding for computer technology and its implications are, the easier you will be able to translate that into object oriented programming methodology and vice versa the latter into these uses.
Don't put too much into memorising things as someone else has suggested, I'm not even sure off hand if variables or constants that are part of a class are conventionally called properties or attributes. Does it even matter in practice? Roughly I see all member of a class as properties of its objects, including methods. Terminological specificity is certainly relevant so don't take this a neglecting that, but if you are learning about particular development techniques it is often sufficient to know that something can be done, rather than dedicate time memorising what it is named or what its syntax is. The use of $this and other language constructs and -functions are something you will simply work in, it is related to scope, you should definitely know what scope is.
I will leave the book recommending to others for this subject.
I added a related post here; http://www.sitepoint.com/forums/showpost.php?p=4754651&postcount=4