Question: I'm writing a custom module for one of my projects and I'm having a bit of an issue. What I'm trying to do is get a piece of data from uc\_cart\_get\_contents() into a variable so that I can use it in a calculation: 

Here's my var\_export:

```
array ( )array ( 0 => stdClass::__set_state(array( 'cart_item_id' => '5', 'cart_id' => '1', 'nid' => '9', 'qty' => '10', 'changed' => '1287074120', 'data' => array ( 'attributes' => array ( 3 => '4', ), 'shippable' => '1', 'restrict_qty' => '0', 'module' => 'uc_product', ), 'title' => 'Chicago Canyon', 'vid' => '9', 'cost' => 1.16, 'price' => 11.16, 'weight' => 0, 'module' => 'uc_product', 'model' => 'chicago-canyon-p-card-p-env', )), )

```

But what if I want to put the model of each item in the cart into a variable, and based upon that variable adjust the item's price.

If it was an array I would do this:

```
$items= uc_cart_get_contents();

$model = $items[model];

```

but that doesn't work, it's a std class. I'm so so lost. Please help!

Answer: 
Apart from the implementation differences, one major conceptual difference is regarding when the classes / type classes as declared.

If you create a new class, MyClass, in e.g. Java or C#, you need to specify all the interfaces it provides at the time you develop the class. Now, if you bundle your code up to a library, and provide it to a third party, they are limited by the interfaces you decided the class to have. If they want additional interfaces, they'd have to create a derived class, TheirDerivedClass. Unfortunately, your library might make copies or MyClass without knowledge of the derived class, and might return new instances through its interfaces thatt they'd then have to wrap. So, to really add new interfaces to the class, they'd have to add a whole new layer on top of your library. Not elegant, nor really practical either.

With type classes, you specify interfaces that a type provides separate from the type definition. If a third party library now contained YourType, I can just instantiate YourType to belong to the new interfaces (that you did not provide when you created the type) within my own code.

Thus, type classes allow the *user* of the type to be in control of what interfaces the type adheres to, while with 'normal' classes, the *developer* of the class is in control (and has to have the crystal ball needed to see all the possible things for what the user might want to use the class).
This slideshow may help you understand the similarities and differences between OO abstract classes and Haskell type classes: [Classes, Jim, But Not As We Know Them](http://www.springerlink.com/index/77607141463259g4.pdf).