Jump to content

Recommended Posts

I'm wondering, should I be using objects though?

 

I thought you said you were using OOP...

 

I'm writing an application using OOP.

 

Your class should contain the methods.  To get to those methods you should create an object of that class.  Is that how you're doing it?  Or am I misunderstanding the question?

One consideration for this is what version of PHP you are using.  If you're using php5 then all objects are passed by reference.  In PHP4 this was not the case.  Hopefully you're using PHP5.

 

If it's appropriate for your application to be dealing with objects then you should be using them.  Only you can answer that question.  For example, if you have a factory class that creates objects, then it would be a very poor design if it did not in fact pass back the object it had manufactured.

 

 

i'm using PHP5.

 

I have an organisation class which has several methods each returning an array of data that is selected from a database and parsed (several calculations are made on the returned data).

 

should i be using objects instead?

i'm using PHP5.

 

I have an organisation class which has several methods each returning an array of data that is selected from a database and parsed (several calculations are made on the returned data).

 

should i be using objects instead?

 

If all you would be using these objects for is to store data (ie; the objects themselves would consist of only properties and no methods) then I don't see why arrays wouldn't be the prefered option.

  • 2 months later...

As devil's advocate, one of the goals of oop is "information hiding".  The idea is that the class should hide the details of the internal data structures.  Passing giant arrays around from method to method is a procedural approach.  I'm not saying that you should change that approach just for the sake of an OOP principle, but if the arrays are large and complicated, it could in fact be a more modular approach to instead instantiate objects that have methods which return the results of computations done on the internal data, as it's needed, with all the internal querying and fetching being private to appropriate object classes.  The idea is that, if you need to change the internal data structures, you don't have a whole host of functions that are suddenly broken because the structure of the data no longer matches what they were working with. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.