Welcome Guest, Not a member yet? Register   Sign In
Objects: Why are they useful?
#2

[eluser]tonanbarbarian[/eluser]
firstly object are not as useful (in my opinion) in web apps as they are in other situations

objects are mainly a way to group common functins together into one cohesive unit that can do some related functionality

to explain the full potential (as i see it) of object let me give an example
if i am creating a java application, one of the things it might need to do is to process an xml file for example.
it will need to read the file, process the data in some fashion, maybe write new data to the file, maybe delete the file if it is no longer needed.

now i could just create a bunch of functions all named similarly to do this (ok so java only works with objects so i could not really do this but bare with me)
but if i create an object to do this it is much more efficient. the object can contain all of the methods to do the various bits of processing, as well as containing any data it needs to do its processing, all self contained.

so the application might load the object, start processing the file etc.
then if the application goes and does something unrelated the object is of course still there and available.
So not for example the app wants to close, as part of the cleanup it might go to the xml object and ask it to delete the file it was working on. If i was using functions to do all of this i would need to have remembered somewhere what file was being worked on, but because im using an object, the object would have its own propery that indicated which file was being worked on and would therefore be able to delete without being told which file.

this is just one example of the advantages of objects.

another big advantage is reusability and portability
if i have another app that needs to interact with an xml file i can just take the entire object code and move it to the new application and it is ready to use.

In the web environment you do not always get all of these advantages of using objects. the reusability and portability is there but because of the stateless nature of a web app you cannot always have the advantage of having an object alays know what is going on
If we look at the previous example and move it to a web environment the upload of the xml, the processing and the later deletion of the file may in fact be all on seperate requests of the webserver. Now there are mechanisms that can be used to retain the state of an object between requests but if they are not used you loose that advantage.

It is the reusability that is the big thing for me that i see as an advantage.

sometimes objects are used in ways i do not like however.
for example i prefer to use the result_array method in the CI database because i do not see the point in using an object as a collection of data when i can just as easily use an array
Also i have seen instances where classes where used more as just a simple namespace rather than a real object
i.e.
Code:
MyObject::myfunction();
This calls a method of an object statically. You do not have to make an instance of the object you can just call the function.
Yes this does have its uses but i prefer not to do that.

these are just my thought, not sure how enlightening


Messages In This Thread
Objects: Why are they useful? - by El Forum - 01-22-2008, 02:59 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 03:18 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 03:32 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:02 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:20 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:22 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:31 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:38 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:41 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:49 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:51 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:51 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 04:52 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 05:01 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 05:06 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 05:19 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 06:55 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 07:15 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 07:23 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 07:23 PM
Objects: Why are they useful? - by El Forum - 01-22-2008, 08:15 PM
Objects: Why are they useful? - by El Forum - 01-24-2008, 05:47 PM
Objects: Why are they useful? - by El Forum - 01-24-2008, 05:59 PM
Objects: Why are they useful? - by El Forum - 01-24-2008, 06:34 PM
Objects: Why are they useful? - by El Forum - 01-25-2008, 02:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB