Improve Your OOP Skills With Symfony
If you've been programming in php for several years, chances are you've come across OOP programming because your application has grown in complexity.
Coding in OOP is a very good move (but not that easy at the beginning). And at the end you'd feel the benefit of code reusing.
What is code reuse?
If you develop more than 2 web applications, you will find code reusing time saving.
There shoudl be common stuff to share like user login, form validation to name a few.
But the difficulty is that you may work in two different environment and you will need to modify the first code in the second application. Unless you are comfortable with high level OOP programming (abstract class, interface, polymorphism, dependency injection, namespace, class autoloading), it is inevitable that you will alter the code.
In fact writing reusable code is not that easy, it needs knowledge of advanced OOP concept.
The best way to start is to download a well known API such as FOSUserBundle and see under the hood. It uses lots of abstraction.
Abstraction is the keyword, this mechanism allows you to write generic methods to be used consistently in different frameworks.
Before you can write reusable code (that you can share as open source), first try to master the key concept of OOP programming such as interface, polypmorphism and design pattern.
Key OOP concept to work on
Here is what i'm working on to master OOP:
Interface and abstract classes
Those two have similarities, abstract classes can only be inherited, but can contain non abstract method, while interfaces are 100% abstract classes. Interface are quite bizarre at first, because they define method ans their signature, but there is no code in the method ! They tell you that using interface can allow you to function in different environment, for example using interface allow you to connect to Mysql as well as PostGrest, or SQLite. Okay, how?
In Java, which is a strongly typed language, (a string is a string, a number is a number and not a string), the polymorphism mechanism allow you to manipulate different type of object.
Design pattern are recipes to solve a problem. For example the singleton design pattern, makes it impossible to instantiate more than once a class. Why? if you don't want to mess up with lots of object and manage memory well then use it. Factory is another one that'll be useful, it is a method of object instantiation without using the constructor of a class, in fact you delegate the instantiation of a class to another class, why? if you one day rename the class or change the class, then you'll only need to do it in the factory class, that will save you time !