Page 1 of 1

learning classes

Posted: Mon Jun 06, 2005 5:42 pm
by malcolmboston
hi people,

sorry to be such a pain in the arse :wink: but at the moment im really looking at extending my PHP knowledge into OOP and im looking at learning classes from the ground up to hopefully convert at least a majority of my current applications to OOP based designs.

now basically ive been looking at here for an explanation on classes,. however that is far too basic and most of the other stuff i have seen go way over my head considering i have no previous experience with classes.

now what im looking for if you can give me a link (ive read the manual ) is explanations on thge following, simple, stuff.

Accessing Classes / methods/ Objects

The use of extend

Explanation of syntax (eg $this->something

Common practices / good coding / being fully OOP

basically, anything that isnt too advanced so i can pick it up whilst i go along and something that will explain the majority of stuff i will need when starting off

Hoping you can help

Eagerly awaiting your reply

Posted: Mon Jun 06, 2005 5:46 pm
by thegreatone2176

Posted: Mon Jun 06, 2005 7:01 pm
by Buddha443556

Posted: Mon Jun 06, 2005 7:25 pm
by McGruff
OOP takes time to learn. In the process you'll probably find that you tear up all your code and start from scratch several times. That's just part of the learning process. Each time you'll be getting better at developing the analytical faculties you need. Good classes - like good functions - are usually classes which do just one thing. Lean clases are also much easier to test.

The sooner you start testing the better. Unit-testing is a vital OOP technique. I can't stress that too highly. There are a whole list of benefits apart from the obvious one of quality control.

I'd recommend SimpleTest (see my signature link) as a testing framework. It's the only one with mock objects (come back to that later - basically mocks let you use testing as a design tool) and there's a nice little web tester which even lets you set form field values and submit forms. I'd be utterly lost without it.

Ignore simplistic talk of classes as "nouns". Move swiftly on when someone starts talking about cars. Resist the temptation to link classes together with inheritance - save that for when one object genuinely *is* of the same general type as the parent.

Study patterns as much as you can. These are tried and tested solutions to common problems including the problem of how to get objects to talk to each other now that you can't just use inheritance. There's a lot of material on the web - it doesn't have to be directly about php programming.

This site is a good start: http://www.phppatterns.com.

Martin Fowler's "Patterns of Enterprise Application Architecture" is essential reading, later. You can see the online catalog here. The book explains in more detail. It's not beginner-level but it's not as hard going as it might at first appear. Fowler talks very lucidly about many programming problems and how to solve them.