oop - PHP Object question -


using simple set of objects example in php.

lets say:

objecta:

properties: descid;

methods: getlistofdata();

objectb:

properties: descid;descname;

methods: getdescnamebyid();

what want know best way descname objectb when objecta 1 calling function within loop.

i'm thinking need instantiate objectb (as new) , pass in objecta.descid objectb.getdescnamebyid method.

for example:

class objecta {        function getlistofdata(){             $myobjb= new objectb();                 while ...                  {                     $myobjb->descid = $row["descid"];                     $mydescname = $myobjb->getdescnamebyid();                      ...                      $i++;                 }       } } 

i'm pretty sure above work i'm not sure if right way, or if there other ways of doing this. there name type of thing? 1 mentioned lazy loading. in php?

bear in mind question needs expansion.

a class recipe. object actual dish made recipe.

so, if need know how recipe tastes, need cook something.

at design time, you're typically thinking classes. i.e. when plan dinner, think want serve, in terms of recipes, not in term of finished dishes. (you don't have dishes until cook them.) said, may take account recipes difficult execute , risky proposition serve.

does make sense?

some questions ask design:

do need objecta, both store id same name? (presumably, they're tied together.)

what's difference between two?

can combined 1 object?

these depends on methods , id is.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -