Monday, March 26, 2012

OOP and Classes

I run a pokemon fan site that uses PHP for fun and I have a friend who also runs a pokemon fan site uses PHP but uses classes. I have also heard about Object Oriented Programming.

I understand that ASP.NET is superior and it is completely OOL. I'd like to switch over one day but my site is fairly popular and is a hobby so I'll need at least 20GB of bandwitdh which I understand is very expensive on ASP.NET hosts so I'm sticking with PHP for now.

Anyway, I am wondering, exactly why are classes and OOP useful? What situations would they be good in?For the most part, its main benefit is re-usability of existing code. You can inherit classes to extend the functionality of other classes, which is great. Also, you can create objects and reuse them on different pages, without having to recode the same thing over and over.

There are a lot of 'primers' to OOP on the web, I suggest you do a search on google.
Hi,

Also, take a look @.Using Object-Orientation in ASP.NET : Overview

HTH
Would the reusability be along the lines of the custom functions that can be created in PHP? In my current php scripts, I use functions to avoid repeating code over and over again.

Also, would someone be able to provide me with an example class and some of the ways it could be used and what those ways are expected to do? I'd like to get an idea of exactly what is going on. ^_^;;
OOP simply brings new life into software development. For example, imagine how to define and name thousands of variables and functions for multiple modules before OOP. Now OOP can create, organize and individualize those modules as objects that contain properties and methods having the same name but different funtionalities. The 4 pillars of OOP are encapsulation, inheritance, polymorphism, and abstraction. OOP projects may be at the start harder to develop, but in the long run much easier to expand and maintain than non OOP ones. This is only my two cent worth. Please further comment and advise. Thanks.

Reusability of code streches over multiple projects. OOP also gives a top down view of your application. most of the time people who don't know how to programme have an easier time to understand OOP then people who have programmed, but programmed in a modular way.

If every user on your website presents a pokemon. you could create a class pokemon. and add properties to it. such as powerlevel, colorofskin, .... you could also create a few other classes such as waterpokemon and firepokemon. these classes will inherit the initial class "pokemon" and also posess the same properties. but you will want to add specific properties for that type of pokemon... for example "firelevel" for a firepokemon or "swimmingspeed" for a waterpokemon. (these properties are specific for that type of pokemon... because a firepokemon can not have a swimmingspeed.) you can also say that a firepokemon starts with a powerlevel of 5 and a waterpokemon starts with a powerlevel of 4. so whenever a person becomes a member of your site... he will have to choose what kind of a pokemon he or she is. when the person chooses to be a waterpokemon then you will create an instance of the class waterpokemon. This way you can easily give him a value for his swimmingspeed and you know he has to have a powerlevel of 4 when he just gets his membership..

this is just a simple example and you would probably do it very differently. But what I mean to demonstrate here is that OOP delivers an architecture of programming... no more messing around... cleaner code and usually also code that is better to understand.

greets,

interw

0 comments:

Post a Comment