Thursday 10 January 2013

What is the Best Approach to adopt OOP in PHP?

What is the Best Approach to adopt OOP in PHP?

What is the best practice for using OOP paradigm in PHP? To what extent, OOP paradigm should be forced? PHP supports OOP. But if we use close to a strict OOP paradigm, we end up compromising on performance and memory.

For example, we have classes named User and UserGroup. UserGroup will have properties like details about Group and contains its members. Best OOP approach is that members of group should be array of instance of User class. Each User has several properties. If we follow OOP approach, we will end up filling all the details of all users in that UserGroup. This will make a lot of queries to database degrading the performance and consume a lot more memory. In face we will not need the details of all users, but couple of them. Or only couple of properties at a time.

So what is the best practice to adapt OOP paradigm in PHP? To what extent, it should be forced?

3 comments:

  1. Can rewrite the query and execute the query with required info which will save space and retriving time

    ReplyDelete
  2. When We want some particular fields from database.

    I think the best way to do it with by creating a function that get data as you want.

    And some other way to write a new query to get some fields from database.

    ReplyDelete
  3. If you are thinking about lot more memory consumption then
    declare a function which will get you appropriate data according to your requirement.

    ReplyDelete