For our school project, we are tasked to define a design document describing the architecture of a PHP application.
We are free te decide what to include in the document.
Our professor suggested, lots of (UML) diagrams.
He also asked us to consider class diagrams, but with care, as PHP is not fully object oriented.
My question: Is a Domain Driven Object Oriented Design feasible for a PHP application? What to consider when doing OO in PHP? What are the pro's and con's? Any helpful resources on OO in PHP and PHP best-practices?
IMHO it's pretty difficult to describe the architecture of any application without knowing what the application is supposed to do. All applications (PHP or otherwise) of any complexity look different.
Secondly, PHP5 gives you classes/objects and the usual plethora of OO gubbings - so to describe it as 'not fully object orientated' is misleading I think. If you mean you can take a procedural approach with out being restricted to objects then yes, but if you wanted everything to be an object then that's your choice.
Is DDD feasible for PHP? Yes, of course. A particular approach to architecture is not usually dependent on technology. Best practices, pros/cons of OO design apply to most languages - PHP leaves you pretty free to decide how to structure your code.
You may find this Best Practices talk from the PHP site useful ;)
Most OO languages currently in use are not fully object-oriented. Every language has idiosyncrasies and gotchas.
So I'd say PHP is OO enough for most simple projects. I worked on the Zend Framework which is designed as an OO class library, with design patterns and such.
One suggestion for PHP is that you should pay attention to its SPL component, which gives you interfaces for many basic classes.
I think it's pretty weak if your teacher said, "put anything you want into the design document, UML diagrams are pretty." Design documentation is an important but woefully undervalued part of software engineering. Your teacher should be showing you examples or templates for good design doc.
PHP can nowadays be described as fully object oriented by choice. It offers everything you need but you are not forced to write OO code.
There are two books which helped me a lot in understanding the OO principles in relation to PHP:
PHP in Action (Manning)
Zend Study Guide for PHP5 (Zend)
OO is first and foremost a design methodoligy.
As such it is possable to come up with an OO design which can be implmented
in procedural langauges. I have seen this done for both C and COBOL projects.
And it has convinced me that nearly all the advantages of OO are to do with design and NOT language implmentation.
So yes you can come up with an OO design with lots of UML (Class diagrams, use cases, swim lanes etc.) and you can implement it in php (using classes or not).
Anyway php is effectively a superset of OO so if you restrict youself to classes
and functions inside classes ( == methods) you have an OO implementation.
The only thing lacking will be interface definitions but it makes very little
sense to define interfaces in a language with such (un)limited type checking.
Related
I am a beginner learning programming, I have learned about variables, data types and so on.
But why isn't it as easy as making an application, software that I imagine? I was confused when reading the programming documentation
And when do we need a method or function from php programming documentation or java, android or other programming language documentation?
Do we have to guess for the method of programming documentation needed to create applications, software, web?
you don't have to learn by heart all those functions, only some of them which you will use most of the time. It is more important to learn concepts, programming paradigms, patterns and other things.
Of course, any language has it's power, so there are some sections you should study.
Not knowing what a language supports is like reinventing the well already implemented in that language.
For example, POO implementation. Some languages allows an object to extend multiple parents (e.g: C++). Other languages will force you to extend only one parent (e.g: Java, PHP); this has and advantage because in Java and PHP there is no diamond problem to solve (check wikipedia for more details)
The better you understand POO the better your design after a model will be.
If you learn about arrays in PHP, and you are asked to implement a sort, look for sort functions in documentation. Before making you own function, search if there is already created one. It is easy to find functions related to data type and objects.
Hope it helps
I am new to PHP but have good OOP idea. I am looking for a good PHP book the Guides to Develop Website in OOP Style.
I have purchased some books that all use Procedural approach to develop the website, or there are few book that show OOP chucks not a complete Webdevelopment Guide.
I need some book(source) that leeds me from Start 2 End of a website in OOP fashion.
The comments above touch-base on this, but I figured I would give a definite "answer" to your question.
The reason you have been having trouble finding a book that shows how to code PHP in an OOP fashion, is that it isn't capable of being programmed that way. At least not alone. PHP is a hybrid language that can do objects, but doesn't have to do objects.
Now, there are a LOT of PHP frameworks out there that help reinforce OOP standards in PHP. It is here that you may find books that are more OO-centric. But any book out there that claims to teach raw OOP PHP isn't worth reading.
If you learned OOP first, as more than a few people are doing today, you have a hard road ahead. You are going to need to unlearn what you have learned about Objects to be able to get PHP. It is a mix. It is a cobbled-together mass of everything in one giant pot.
This power comes at the sacrifice of formality and standards. OOP is about sacrifice of power for formality and standards.
Good luck.
EDIT
To expand on how PHP is not OO alone.
What I mean is that, as I said later in the answer, using a framework that helps enforce OOP principals can make PHP function like other OOP languages, or at least more closely like it.
I should also clarify my C++ not being OOP comment. C++ is in exactly the same boat as PHP, only it has been around long enough that OO has become a true standard and is well-practices throughout the industry at large. PHP doesn't have this. There are almost no strictly OO large-scale applications built in PHP. Working with strict OO standards in PHP on the high-end will grind your application to a hault.
Compare with real OOP languages/frameworks. Ruby, Smalltalk, so on. Or even almost-totally OO languages like Java and C#.
I would recommend this book:
Matt Zandstra - PHP Objects, Patterns and Practice, Third Edition
It is largely OOP focused, at the same times it sheds light on the shortcomings/limitations of OOP in PHP.
"Object-Oriented PHP" is a book: http://objectorientedphp.com/
I have been reading around the definition of OOP and couldn't get why PHP is considered object oriented.
Can this have anything to do that the "basic level" of PHP isn't and more advanced features are?
OO features were added to PHP in stages through versions 3-5, after much of the standard library had already been created and the language was already established. Background
For this reason the standard library is not object-oriented and so everyday PHP scripts need not use any OO-style features at all. Although PHP by now has most of the standard features of an object-oriented language, many authors don't use them.
Library functions added to the language later continued to use functional style for consistency, though many extension modules do use objects.
Almost any language that allows you to create and instantiate classes can be considered object oriented.
PHP has these capabilities, but doesn't really stretch them. You can use OOP to help your code, but it isn't required. Java and C# barely allow you to write non-OO code, as everything must be in a class.
Can this have anything to do that the "basic level" of PHP isnĀ“t and more advanced features are?
You could say that about just about any OO language. The general definition of OO code is where you create classes and instantiate them in your code, calling methods on them from other classes. Nothing stops you from using only static methods or one super class with a 'run' method that only calls other methods inside the class, both of which would definitely NOT be object oriented. As far as I know, there aren't any languages that say "You must create classes and instantiate them or you will be banished!" (I haven't looked into Smalltalk though).
Beginners often learn the basics while putting all their code in just one method that gets called at the stat of the program. Once they get to more 'advanced' features like methods and classes, they are offered other options.
There is already a sufficient (and accepted) answer here, but I thought I'd throw another log on the fire for clarity's sake.
The "class" keyword (and the enforcement of its ubiquity, as in Java) does not Object-Oriented Programming make. As CrazyJungleDrummer pointed out, it is perfectly feasible (and all too common) to write entirely procedural code in something like Java; the fact that the code lies between curly braces in a class called HelloWorld doesn't change that fact. And just hiding a bunch of functions in a class and calling them static methods isn't OOP either -- it's namespacing.
Think of a proper object as a struct (or "custom type", depending on your previous language exposure) that knows what to do. Objects are data that you don't (or shouldn't) act upon directly; you ask them to do things to themselves, and you ask them to tell you about themselves. You create entities and pass messages. OOP is about treating your data like it's all grown up and can handle itself. It's not about where the main line of code lives, but how data are treated.
Oh, and one more thing -- even in a language that is more obviously canted toward OOP, real OOP is not always the right approach. It's all about the data.
You can write classes with PHP, but most of the core features are not object-oriented.
It's been a long time since this question but I came upon this article and wanted to shre the author's point of view.
PHP is not object oriented!
This answer is inspired by this Man and his answer.
Object-Oriented technology is often described in
terms of encapsulation, polymorphism, and inheritance. But
these are only identity.
If object-oriented technology is to be successfully
it must emphasis on the object.
When we say Object-oriented or Object-orientation it can refer to several things:
Object-oriented analysis and design[OOAD]
Object-oriented design[OAD]
Object-oriented database
Object-oriented modeling
Object-oriented operating system
Object-oriented programming[OOP]-->topic of concern
Object-oriented software engineering
Object-oriented user interface
What Pure Object Oriented Programming Language[OOP] is?
Alan Kays["Considered by some to be the father of object-oriented programming"] [Defination]5 link by Gordon:
EverythingIsAnObject.
Objects communicate by sending and receiving messages (in terms of objects).
Objects have their own memory (in terms of objects).
Every object is an instance of a class (which must be an object).
The class holds the shared behavior for its instances (in the form of objects in a program list)
Now clearly it can be seen Java,C++ and PHP violates rule 1?Why bcoz int, float etc. (there are a total of eight primitive types). so it cannot be Object oriented in strict sense but some folk's considered it as OOP.
The general approach of OOP is to view a software system as a collection of interacting entities called "objects" each of which is defined by an identity, a state described in terms of member variables, and a behavior described in terms of methods that can be invoked
What OOP is not?
Object-Oriented technology is often described in
terms of encapsulation, polymorphism, and inheritance. But
these are only identity.
An Object Oriented system, language, or environment should include at least Encapsulation, Polymorphism, and Inheritance.
Polymorphism and Inheritance are certainly patterns that facilitate
OO programming, but not only bound to it
The object-oriented paradigm isn't completely the domain of
high-level programming languages -->may topic of debate but i came
across this OOP in Assembly
Uncle Bob aka Bob Martin in his lecture shows How C implements Encapsulation,Inheritance,and Polymorphism LINK
OO is based on modeling real-world objects // For Marketing purpose
Difference Between OOP and Functional?
This may be not be perfect answer but i gave a try,Thnks to knowledge of valley.
Note:
Images are randomly found on google
I'm looking for a good framework for PHP and see most offer the MVC approach, are there any other (or better) design methods/approaches that would be considered more efficient or best practice? MVC is starting to look dated but I wanted to know if it's still considered the industry standard.
MVC is still the industry standard for every Object Oriented web development language.
However you are afforded some alternate routes:
Micro Frameworks (Google Them) (which most often still use MVC design patters, just not as formalized and some not in an Object Oriented fashion)
Event-Based Frameworks (like PRADO)
However beyond those routes you are a bit out of luck as far as I know.
Thanks Xeoncross, forgot to add the "micro usually are still mvc" caveat
Well, in all truth MVC is actully misleading when it comes to most frameworks. I don't know of any PHP system that is only based on Models, Views, & Controllers. Most of them also use functions, libraries, configs, and caching levels as well.
MVC is merely a starting point stating that abstraction of your CRUD from your business logic and views is good a good thing! From there you can abstract as much more of the system as you want from template parsers to libraries that calculate physics.
I would recommend symfony framework as my ideal ;)
http://www.symfony-project.org/
The only PHP frameworks that I am aware of that are well tested use the MVC pattern however there has been some web based frameworks that use the Naked Objects pattern for other languages like Java.
In case you are interested it looks like there is at least one Naked Object framework under way for PHP also here:
Naked object PHP blog
I will like to see if everybody could share any good training sources on OOP on PHP language.
Good Training Sources for OOP (Object Oriented Programming) PHP, anyone ?
I've seen numerous tutorials, mostly superficial, some of them bad.
Please share anything good either commercial or free, Video or Written.
I love the PHP Manual's guide to OOP. It's to the point and has many examples.
This is your absolute best bet, in my opinion. The documentation here includes both technical explanation as well as useful examples and plain-english wording.
PHP.net/oop
Keep in mind however that PHP OOP is still in relative infancy, and there will no doubt be many things that are confusing to other OOP implementations.
Lynda.com have a good video course:
Lynda - PHP with MySQL Beyond the Basics
http://www.lynda.com/home/DisplayCourse.aspx?lpk2=653
It's a bit more on the advanced side of OOP, since it's about design patterns, but I really like Martin Fowler's Patterns of Enterprise Application Architecture (http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=sr_1_1?ie=UTF8&s=books&qid=1255402272&sr=1-1). And you can never go wrong with the Gang of Four's pattern book (http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/)
The nice thing about learning patterns is that they're language agnostic. Learn a pattern, use it in (almost) any language :)
For starting the php phpmaual is the best thing that is available.
You can also try http://w3schools.com
If you wants some more resources on the oops concept and examples then you can go to
http://www.phpclasses.org/
Here you will find some incredible projects of php.
Since is conceptual and not language specific, look for any good OOP resource in any language and try and make it work in PHP.
Look at concepts like design patters, unit testing and domain driven development and you will expose yourself to a lot of OOP knowledge.
Start using libraries like Zend Framework and Doctrine PHP ORM in your PHP projects. They are object-oriented and by using them you will develop a greater understanding.
Also check out phpPatterns and the c2 wiki.
-Sam
You can try Codeacademy, it provides with tutorials in many languages : http://www.codecademy.com/fr/tracks/php