开发者

Help Understanding Object Orientend Programming OOP

开发者 https://www.devze.com 2023-02-09 04:34 出处:网络
I\'ve been reading up about OOP on several websites & looking though (SO and I find it hard to find any that shows a decent example of a full OOP PHP application. They give examples using cars but

I've been reading up about OOP on several websites & looking though (SO and I find it hard to find any that shows a decent example of a full OOP PHP application. They give examples using cars but It doesn't resonate well with me in regards to putting it to actual use one day.

Can someone show me a good full example off OOP that could be used in a real website scenario. I know I may be asking for a lot but It will really help.

开发者_运维百科

Or is there a diagram somewhere that shows a real life relationship between methods, classes, Objects, constructors etc.

I know it's not simple to explain but It would appreciate an attempt.

Thanks in advance


What if you change "car" to something a little more familiar on the web?

$post = new BlogPost();
$post->setTitle($_POST['title']);
$post->setBody($_POST['body']);
$post->setTags($_POST['tags']);
$post->save();

Same idea. You have a BlogPost class which encapsulates the representation and manipulation of blog posts. It hides things like turning a comma-separated list of tags from the user into separate rows in a tags table when saving the post, and just how the post is saved. You could switch from saving them as text files to saving them in a database without changing all the code like above where you read or write posts.


You could try using Symfony or Yii. You'll be doing OOP in them, plus they both have sample applications you can get started with quickly.


Bruce Eckel's freely available book "Thinking in Java" contains a great introduction to the object oriented world (chapter 1). Though it contains some Java references, you'll later see that the conceptual fundamentals of OOP are the same in C++, Java, PHP, or any other modern programming language.


I think these books can be a good start point

PHP Objects, Patterns, and Practice, Second Edition

http://www.apress.com/book/downloadfile/3872

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号