Welcome! Log In Create A New Profile

Advanced

Classes

Posted by 42609852 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Classes
April 22, 2013 05:23PM
hope this works...
3rd time lucky... (sorry for messing up on wrong forum)


Hi, hope you can help...
is the follwoing posible...?
a good idea (or bad idea)?

to have a property of my class, be an aray of obj of another class?

Language: PHP
Class Fixture{ function __construct($ID,$Name,$Date,$Team){ $this->ID=$ID; $this->Name=$Name; $this->Date=$Date; $this->Team=array(); //empty array, to later be filled with a method that will add player obj $this->game_Pos="";} } Class Player{ function __construct($ID,$Name,$Surname){ $this->ID=$ID; $this->Name=$Name; $this->Surname=$Surname;} }

so that when I create the fixture obj... I can have a method that adds player obj to the team Property?
am I overthinking it...
not sure if this is bad practice?
avatar
Mac
Re: Classes
April 23, 2013 08:42AM
If you go the OO route you will be on your own...

All you have here are constructor functions that sets give the properties values..... they do not relate to your questions, which is confusing sad smiley add a player object to the team property?
Re: Classes
April 23, 2013 08:48AM
suppose it doesn't help going complicated then asking for help digging myself out the whole eye rolling smiley

just to clarify the question and why I added the constuctor function (but no need to answer.... played around, and whether I am doing right thing or not, its working)
well the question is the constructor function of the fixture creates a property that is an empty array
is it ok to then have a function to fill the array with a bunch of player objects... (as the team will essentially just be a bunch of player?)
avatar
Mac
Re: Classes
April 23, 2013 08:52AM
You mean fill the array with player id's, not objects? You will need a method to do that, as the constructor just sort of sets the initial values.
Sorry, only registered users may post in this forum.

Click here to login