Page 2 of 2
Posted: Fri Apr 14, 2006 2:18 am
by Oren
As a reply to the last posts:
arborint: what do you thing I'm doing with the class? creating it for fun? of course I use the new statement, otherwise how will I use the classes I create?
Buddha443556 (and all the rest): When I talked about more clean and simple code I meant to clean and simple code thanks to the fcat that I reuse the calss and just including it in my main file that I'm working with of course.
Reuse is the main reason for using OOP - it would be stupid to connect to the database each time you want to pull some results and it will also be stupid to handle errors on a per-file basis.
Posted: Fri Apr 14, 2006 7:18 am
by Buddha443556
Code reuse is probably the simplest and easiest to achieve though.
... only when compared to other forms of reuse does it even appear to be simple or easy. Probably not simple or easy for the novice.
Reuse is the main reason for using OOP ...
OOP encourages code reuse through inheritance. I'm not sure if what you're referring to is this kind of code reuse or component reuse? Code reuse through inheritance is a powerful benefit of OOP though.
Posted: Fri Apr 14, 2006 7:27 am
by Oren
Hmm... I thought that by "reuse" you were talking about a code that you use again and again like connecting to a database... weren't you?
Posted: Fri Apr 14, 2006 1:27 pm
by Buddha443556
Hmm... I thought that by "reuse" you were talking about a code that you use again and again like connecting to a database... weren't you?
I was referring to
Extents which is PHP way of implementing inheritance. It's just another form of code reuse, Java's class library would be an example. [Is there a good PHP example? Anyone?]
Abstractions and
Interfaces are related subjects from PHP5.
Posted: Fri Apr 14, 2006 2:11 pm
by Christopher
Oren wrote:arborint: what do you thing I'm doing with the class? creating it for fun? of course I use the new statement, otherwise how will I use the classes I create?

My point is that creating classes and object does not necessarily mean that you are using OOP.
Posted: Fri Apr 14, 2006 2:21 pm
by alex.barylski
arborint wrote:Oren wrote:arborint: what do you thing I'm doing with the class? creating it for fun? of course I use the new statement, otherwise how will I use the classes I create?

My point is that creating classes and object does not necessarily mean that you are using OOP.
Agreed...
Posted: Fri Apr 14, 2006 2:24 pm
by Oren
arborint wrote:My point is that creating classes and object does not necessarily mean that you are using OOP.
Oh, ok I see what you are trying to say now. What means that I'm using OOP then?
Posted: Fri Apr 14, 2006 3:08 pm
by alex.barylski
Oren wrote:arborint wrote:My point is that creating classes and object does not necessarily mean that you are using OOP.
Oh, ok I see what you are trying to say now. What means that I'm using OOP then?
It can't be explained fully...
It, like anything complicated, takes time and more importantly experience...
OOP is a paradigm...methodology...idealogy...and so on...
It's a further abstraction from the machines we program...
When used properly it makes code more reusable, understandable, organzied, etc...
It's no hidden secret that a complicated problem can be broken into smaller more understandable parts, which OOP lends it self to nicely, more so than procedural does.
The concept of an object suggests reuse...think components on a car...
A caliper can quickly and easily be replaced, along with it's Rotors, pads, shoes, etc...
Because a car is componentized, when something breaks, it's replaced easily as opposed to buying a new car.
OOP and components are leading software development towards that same goal...
The most important thing when learning OOP is probably proper object discovery...
Looking at a problem and breaking that problem into smaller problems and so on...Solving those problems using classes and discovering how each of those classes may or may not interact and how they should interact (is a versus has a relationships).
Cheers

Posted: Fri Apr 14, 2006 3:15 pm
by Oren
So can you please post some examples to show me when do you use OOP and for which kind of problems?
Thx.
Posted: Fri Apr 14, 2006 3:39 pm
by Christopher
Oren wrote:Oh, ok I see what you are trying to say now. What means that I'm using OOP then?
Like Hockey says, it is a complex subject, but I can give you a few really basic things to look for.
- Are you using your objects like data or function libraries? They are data. One clue is if you are passing objects around.
- Are you using composition? Do your objects use other objects to do their work?
- Are you useing polymorphism? This builds upon composition where the user of an object does not care about the type, only that the necesary methods are supported.
- Are the dependencies between your objects clear? Clear dependencies often go with clear purpose.
- Are your classes large or small? Small classes often indicate that the purpose is focused.
Others can add more, and some (like the last two) are for any kind of programming.
Posted: Mon Apr 17, 2006 1:52 am
by alvinphp
Oren wrote:So can you please post some examples to show me when do you use OOP and for which kind of problems?
Thx.
I personally use it for everything larger then one page. OOP is a whole way of thinking. Your objects are living. As soon as you create an instance of your class (class = blueprint on how to create your object) you have an object to work with. Many people know all the technical aspects of OOP, but I don't think they fully understand and build in an OOP frame of mind. I admit it took me a little while to grasp the concept myself, but when I did it was like an epiphany. All the technical aspects of OOP now made complete sense.
I tried explaining OOP a few times here, but I give up because it takes more then a few posts to understand OOP. For OOP in PHP I highly recommend PHP5 for Professionals by Wrox. This book assumes you already have a good understanding of PHP.
Posted: Mon Apr 17, 2006 3:38 am
by Oren
You are all keep talking about 'OOP frame of mind' and such, but I haven't got any good explanation about this 'frame of mind'.
Is there anybody who can explain what it is exactly? (in a brief)
Thx.
Posted: Mon Apr 17, 2006 7:22 am
by Buddha443556
Oren wrote:You are all keep talking about 'OOP frame of mind' and such, but I haven't got any good explanation about this 'frame of mind'.
Is there anybody who can explain what it is exactly? (in a brief)
Thx.
To me it's about grammar. In a Top Down Design, the focus is on verbs, the actions. The program is decomposed into smaller and smaller actions. In a OOD, the focus is on nouns, the objects. The program is decomposed into objects or groups of objects (abstraction). Nouns will form the classes and data members while verbs will form the methods of the classes.
Someone around here is always telling people the first language they need to learn is English, they're correct.
Posted: Tue Apr 18, 2006 4:38 pm
by alvinphp
Oren wrote:You are all keep talking about 'OOP frame of mind' and such, but I haven't got any good explanation about this 'frame of mind'.
Is there anybody who can explain what it is exactly? (in a brief)
Thx.
It means to code your applications as living objects. Living in that once you create the instance of your class you now have an object (we will say a car) that you can now use. If you run the method to turn off your engine then right after run another method to step on the gas the car will not move forward as your engine is off. You should not have a method to check if your engine is off or on as this should be an attribute of your object that changes when you run the method to turn your car on/off. (well you have an accessory methods, but I am trying to keep it simple)
As people said you deal with nouns where the actions of the noun is called a method and the description of the noun is called an attribute. And as attributes change (in your call) it will effect the actions you do.
Posted: Tue Apr 25, 2006 3:06 am
by rsmarsha
Wow, what a response.

Thanks for all the pointers guys.
I have looked at some and as people have said, it's all a bit confusing at first. My main problem at the moment is i work on one site for a pc company. All the code with a few minor exceptions is custom for each page, no one page is the same as another. I need to get a new job, lol.
I don't really have a personal project at the moment large enough to test it all on, but i'll do some reading up. I tend to learn by doing though, so when i get the chance i'll try to put this into practice. I guess when i change jobs into a web dev agency i'll need to build up a code library of my own, and classes will be useful. The theory of oop will come with the larger projects.
I also need to wait until my host puts php5 on, to use a lot of the new bits.
