What Classes would you define for a shopping cart in OO concept?

I’m trying to do my school project in OO. But I end up using OO to break the functions into classes rather than using it as objects. In another words, I might as well write my methods as static functions.

Lets say a Staff has the ability to delete members, view/add/edit products and inventory. How would you define the class?

And lets say you have a ProductDAO class which fetches all products in the DB with this statement, SELECT * FROM products, would you break them up into individual Product objects?

That is, something like $prod1 = new Product(“someProdAtrrib”); ?

I think I shouldn’t think how a user will interact with the application when doing OO?

A user interacts with functions/methods. That is they perform actions like adding/deleting/viewing. They don’t really interact directly with objects?
Which is why I think my program works even without creating objects.

Is this a just a conceptual project, or is it supposed to actually function? My answer would really depend on the above, and which layer you were looking at.

Concept Code (controller action)

try {
    $product = $this->productModel->fetchById($productId);
} catch (ShoppingCart_Exception $e) {

Inside the buy method, the user and product objects could interact, and throw exceptions upon the many possible error conditions (NSF, out of stock, etc.) Try to think of things in terms of real life objects. Inside these classes, the code may be more complicated, but it’s a good starting point.

I always start on the outer interfaces of the code, and build the implementation later. Focus on how the objects should interact.

Hope this helps.

It sounds like a Staff is a role with permissions to do this things, so it could be wise to assign certain permissions on a “role”…
An easy solution could be to simply check that the user is in that role on the pages that they can delete members etc…

php: user->IsInRole(‘staff’){ product->add(…) }

A more complicated thing can be to create an ACL …

Yes that is wise to do, however think of if you want to be able to actually update or delete the objects that you return in the list, like: $prod1->delete() or simply read its values like $prod1->getname()

As SirAdrian showed in his example It could be a good idea to think of users
interact since they can have behaviors like $user->isAuthenticated() or $user->AddItemToShoppingCart()