I am a developer in PHP technology, I am aware of almost all the basics of OOPS, but still cannot find out the way to apply these concepts over a procedural programming.
I do it in very orthodox way, but I don’t know why I am coding it in that way. I never have reasoning to justify my OOPS applications, which has inferred me that I am worst in OOPS, Please help me guys to understand the application of OOPS.
6
Firstly, it’s pretty difficult to summarise something as complicated as OO in a few sentences. I would recommend that you find yourself some good books on the topic, and read them, while practicing what they preach.
That said, a short explanation would be: object orientation is simply one particular way to structure code. You are trying to create pieces of code which are loosely coupled and cohesive. Loosely coupled meaning that they don’t unnecessarily rely on each other, and cohesive meaning that things that should be close together, are. Encapsulation is the principle of making a class appear as simple as possible to the outside world, while containing whatever complexity is necessary, inside itself. You are also trying to reduce repetition and duplication of code and logic (DRY, etc).
These are the general principles, and you should spend a lot of time trying to understand why these are good principles, and what they mean. They tend to be fairly universal, so you will be able to apply it outside of OO. Once you have these “basics” (and they are not simple) down, you will understand the whys, and can make your own judgement calls on design. Unfortunately, I can’t think of any way to go into any more detail without writing pages and pages, so I’ll leave it at that. Last tips: try to make sure you understand why you are doing something; but be patient – I’ve almost never seen anyone who was more than barely competent in OO with less than 5 years of experience.
2
Its really very basic. Its about binding together the data and the logic that manipulates that data.
So you have:-
- Encapsulation.
all logic and data definitions related to the object are encapsulated in a class. - Interfaces.
some data and methods need to be exposed to the rest of the world if the class is to be useful. Data and Methods so exposed form the interface. - Inheritance.
You can make a more specialized class by inheriting the features and methods of a base class so you don’t need to code the logic again.
All the other stuff Polymorphism, Abstract Classes, Sub Classes, Super Classes is pretty much icing on the cake and varies greatly form language to language.
8