What would be the best (or, correct) way to learn PHP, or any other (object oriented) OO programming language? Just reading books or tutorials may do no good unless we try it for ourselves. When we start coding, often we are faced with questions such as, where to use procedures/”scripts” to get our work done and where to use Objects. This may be a daunting task if we are not clear about the design that is meant to solve our problem.
As a “newbie” we might be carried away by the scope of OO programming. Jumping onto the OO bandwagon indiscriminately, may end us up with a bloated code. On the other hand, we might miss the real opportunity to create a reusable code, in order to get our work done as quickly as possible. So, how do we decide if a needs OO approach or not? Needs some cool headed thinking. We may ask ourselves some question. Why did we need objects in the first place? Because objects are portable and reusable. (Objects have several other properties as well that makes our life easier. e.g. polymorphysm, which I would emphasize later.) Asking these kind of questions may give use a clue as to where do we need to use objects. If a task/operation is repetitive we may try to model them as objects. If a big data set is to be passes across various methods, we may choose to model the data set as an object and carry on.
So, what are the questions that we should ask before we start coding?