|
Posted by Dikkie Dik on 03/21/06 01:47
<snip>
> Thanks for the advice. Some useful ideas in there. Now I guess I need to
> just get my head around the physical language.
>
> So, if I was building a cart from scratch I'd think ....
>
> session handler
> opendatabase
> displaycart
> addtocart
> displayshop
>
> Then I'd need to start building it. Is this stage 1? Is this how you'd think
> it out?
>
Well, it's a good start, although objects tend to be more "things" than
"actions". The actions on the objects are its methods. So you could have
a Shop object and a ShoppingCart object, for example. The Shop object
would probable have a ShoppingCart inside, so if you would give the command
$objShop->display();
the shop object itself would probably call $objShoppingCart->display()
as a part of that action.
Due to the stateless way web servers work, the ShoppingCart must be
"refreshed" from the session and/or the database at every page buildup.
This initializing code can be put in the constructor. If you would
decide to use separate objects for the session or the database, you
could pass them as arguments to the constructor.
So an adding to a cart could look like:
$objShoppingCart = new ShoppingCart($_SESSION, $dbs);
$objShoppingCart->add(....);
In the class ShoppingCart, there would be functions
public function __construct($session_array, $database)
{ // code to read items from the session and the database
}
public function add(....)
{ // code to add an item to the shopping cart.
}
public function display()
{ // code to display the contents.
}
Have fun.
Navigation:
[Reply to this message]
|