php - Proper way of creating a list of objects -


i wondering on best way go creating list of objects.

currently, have class deals orders. in order retrieve order needs call api provided with. api calls expensive point make call returns 5000 orders faster make 2 separate calls 2 separate orders.

because of this, built class initialized 2 ways, 1 way allows me pass order number , initializes itself, if pass array, uses data array create object.

now have functions getorderlist($startdate, $enddate) make 1 call api , fill array full of order objects returned can stuff them.

this feels 'hacky' me, wondering if there accepted way of doing trying accomplish while being more oop.

note: personal project using learn best practices rather hear 'should have done' vs 'what can here'

it sounds fine me in case. if want "more correct" (which can be), might want make ordermanager object has class method manage collections of orders. example call might this:

<?php class ordermanager {     public static function getlistbydaterange($startdate, $enddate) {         // ...         return $listoforders;     } }  $orderlist = ordermanager::getlistbydaterange($startdate, $enddate); ?> 

this called mediator pattern. gives flexibility of extending manager class have other forms of querying later or if find doing lot, can make generic manager class , specify types of objects it'll work in subclass.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -