|
Post by (/iPokemon/) on Jul 16, 2011 5:14:28 GMT
class iPokemon { public $pokemon; function __construct($new){ $this->pokemon = $new; } function wildPokemon(){ return $this->pokemon; } } $pikachu = new iPokemon("Pikachu"); echo $pikachu->wildPokemon();
Isn't that OOP xcessive?
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
Post by Jordan on Jul 16, 2011 5:45:50 GMT
class iPokemon { public $pokemon; function __construct($new){ $this->pokemon = $new; } function wildPokemon(){ return $this->pokemon; } } $pikachu = new iPokemon("Pikachu"); echo $pikachu->wildPokemon();
Isn't that OOP xcessive? Yes, but $pokemon should be private. You can have public properties in OOP, but in this case you are using a getter to return a copy of $pokemon's value (assuming it's a primitive and not a reference to an object) which implies you want it hidden from the outside world. Basically, there is no point in having a getter function if the variable is going to be public because the outside world can access it directly (which is usually not what you want). One of the key ideas behind OOP is being able to have properties and methods that aren't known to the outside world. Only the object needs to know about its internals, and the outside world can simply create an instance of the class and use it without having to know how it works. This becomes more and more important when you are working on large projects that involve many programmers. For example, say you want to create two threads in your program. In a language such as Java, this is very simple. // Create Threads Thread thread1 = new Thread(...); Thread thread2 = new Thread(...); // Start Threads thread1.start(); thread2.start(); You don't have to know about all the internals to utilize the thread class. ( xcessive - Yes, you have to either implement the Runnable interface or extend the Thread class, but I'm trying to use this as an example).
|
|
|
Post by (/iPokemon/) on Jul 16, 2011 6:31:23 GMT
Well, going off what xcessive had, I was just making another version. Yes, it could be private, and perhaps protected if it doesn't want to be called by the outside world.
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
Post by xcessive on Jul 16, 2011 6:47:39 GMT
Well, going off what xcessive had, I was just making another version. Yes, it could be private, and perhaps protected if it doesn't want to be called by the outside world. Protected is a completely different thing - its a package based type. What you did shows one aspect of OOP basics, and yes, its correct so you are getting the idea I guess. I suggest you read Jordan's post carefully though because he gave a very concise and /good/ explanation of what you need to understand to use objects/classes effectively - data hiding. One you grasp that inheritance and polymorphism make more sense, and those three combined make OOP.
|
|
Justin
Elite Poster
Pure Awesomeness[M:0]
In Memory of those killed in the 9/11 attacks
Posts: 277
|
Post by Justin on Jul 16, 2011 16:09:03 GMT
Looks rather confusing :b
|
|
|
Post by (/iPokemon/) on Jul 16, 2011 21:01:22 GMT
Lol, thread takeover ftw. It isn't that hard after, as the above has stated, the hidden variables that are modified by the script itself. Your usersystem, upon reading over it, was very good for how much experience you have. -never posted this, just PM'd this to you-
|
|
Cam
Administrator
[M:5000]
Posts: 6,381
|
Post by Cam on Jul 17, 2011 22:30:58 GMT
You guys should make a new thread
|
|
Justin
Elite Poster
Pure Awesomeness[M:0]
In Memory of those killed in the 9/11 attacks
Posts: 277
|
Post by Justin on Jul 23, 2011 0:02:13 GMT
Update**
There hasn't been an update on this thing for a while, or any posts, so here's an update on what I am doing with this thing:
I have decided to edit it, to make it better but not completely recode it, and I am also going to make a forum system, with this usersystem in it (:
|
|
|
Post by (/iPokemon/) on Jul 23, 2011 17:59:01 GMT
Update** There hasn't been an update on this thing for a while, or any posts, so here's an update on what I am doing with this thing: I have decided to edit it, to make it better but not completely recode it, and I am also going to make a forum system, with this usersystem in it (: Oh boy, have fun with that! xD
|
|
Justin
Elite Poster
Pure Awesomeness[M:0]
In Memory of those killed in the 9/11 attacks
Posts: 277
|
Post by Justin on Jul 23, 2011 19:12:53 GMT
Best way to learn is to go for the harder stuff :b
|
|
|
Post by (/iPokemon/) on Aug 7, 2011 14:50:14 GMT
Best way to learn is to go for the harder stuff :b Which also leads to discouragement, which could cause you to stop the project
|
|
Justin
Elite Poster
Pure Awesomeness[M:0]
In Memory of those killed in the 9/11 attacks
Posts: 277
|
Post by Justin on Aug 7, 2011 15:44:21 GMT
nope not stopping it :b , I don't quit :b
also usersystem v1.5 is being worked on which includes - A pm system (finally) a list of registered members (don't know why I didn't do that before) a few upgrades Number of posts a user has made (jORUM integration) 5 latest threads they have participated in a points system (karma) user groups signatures and a few back-end upgrades
|
|
|
Post by (/iPokemon/) on Aug 7, 2011 16:12:27 GMT
nope not stopping it :b , I don't quit :b Hah, that's going to come back and bite you in the butt one day
|
|
Justin
Elite Poster
Pure Awesomeness[M:0]
In Memory of those killed in the 9/11 attacks
Posts: 277
|
Post by Justin on Aug 7, 2011 16:21:54 GMT
Probably :b but it's not right now xD
|
|
|
Post by (/iPokemon/) on Aug 7, 2011 16:24:32 GMT
Probably :b but it's not right now xD Haha, okay then
|
|