ProductProxy Class Reference

The class ProductProxy is a virtual proxy of class Product. More...

#include <Product.h>

List of all members.

Public Member Functions

 ProductProxy (const ProductProxy &pp)
 ProductProxy (int aPid)
 Constructor with given ID.
 ~ProductProxy ()
 Default destructor.
auto_ptr< CategorygetCategory ()
 Returns product category.
int uniqueID () const
 Return the product unique ID.
float getPrice ()
 Returns the price of this product.
string getName ()
 Returns product name.
string getDescr ()
 Returns product description.
int getAvailability ()
 Return the product availability.
bool isValid ()
 Checks if the instance of product is valid.
ProductProxyoperator= (const ProductProxy &)
 Assignment operator.

Static Public Member Functions

static vector< ProductProxy * > & catalog (int aCid=0)
 Return the list of products of a given category.

Protected Member Functions

ProductgetProduct () throw (InvalidArgument)
 Obtain a real instance of the Product.

Private Attributes

Product_theProduct
int _pid

Friends

ostream & operator<< (ostream &, ProductProxy &)

Detailed Description

The class ProductProxy is a virtual proxy of class Product.

There could be situation when only a proxy of the real product is needed and not all its data are requested: for example, think at new order placing, where only product ID is asked to be known. Whenever other information are requested, ProductProxy provides lazy creation of the product and forwards the request.

See also:
Product, getProduct()

Constructor & Destructor Documentation

ProductProxy::ProductProxy ( const ProductProxy pp  ) 

Referenced by catalog().

ProductProxy::ProductProxy ( int  aPid  ) 

Constructor with given ID.

Construct an instance of ProductProxy by specifying product unique ID.

Parameters:
[in] aPid Product unique ID

References _pid, and _theProduct.

ProductProxy::~ProductProxy (  ) 

Default destructor.

Dealloc instance of real object if it was allocated.

References _theProduct.


Member Function Documentation

vector< ProductProxy * > & ProductProxy::catalog ( int  aCid = 0  )  [static]

Return the list of products of a given category.

Parameters:
[in] aCid The category ID
Returns:
A vector of ProductProxy
Note:
Pass zero as category ID to get all products

References Database::getConnection(), Singleton< Database >::instance(), ProductProxy(), and SQL_CATALOG_PROXY.

Referenced by UserMenu::printCatalog().

int ProductProxy::getAvailability (  ) 

Return the product availability.

Returns:
How many pieces of this product are available

References getProduct(), ManagedObject::intForKey(), and KEY_PRD_AVAILABILITY.

Referenced by Basket::addProduct().

auto_ptr< Category > ProductProxy::getCategory (  ) 

Returns product category.

Returns:
An instance of class Category which the product belongs

References Product::getCategory(), and getProduct().

Referenced by UserMenu::printCatalog().

string ProductProxy::getDescr (  ) 

Returns product description.

Returns:
The product description
See also:
getProduct(), Product()

References getProduct(), KEY_PRD_DESCR, and ManagedObject::valueForKey().

string ProductProxy::getName (  ) 

Returns product name.

Returns:
THe name of the product
See also:
getProduct(), Product()

References getProduct(), KEY_PRD_NAME, and ManagedObject::valueForKey().

Referenced by operator<<(), UserMenu::printCatalog(), and UserMenu::showUserProfile().

float ProductProxy::getPrice (  ) 

Returns the price of this product.

Returns:
The price of the product
See also:
getProduct(), Product()

References Product::getPrice(), and getProduct().

Referenced by Basket::addProduct(), and UserMenu::printCatalog().

Product * ProductProxy::getProduct (  )  throw (InvalidArgument) [protected]

Obtain a real instance of the Product.

Concrete creation of an instance of Product class; when client programmer tries to access to some ProductProxy methods, such as getPrice(), a call to this method ensures that the product is instantiated only we really needed.

Returns:
A pointer to class Product

References _pid, _theProduct, Database::getConnection(), Singleton< Database >::instance(), and SQL_PRODUCT_PROXY.

Referenced by getAvailability(), getCategory(), getDescr(), getName(), getPrice(), isValid(), and operator<<().

bool ProductProxy::isValid (  ) 

Checks if the instance of product is valid.

Returns:
True if the instance is valid, false otherwise

References getProduct().

Referenced by UserMenu::showProductDetail().

ProductProxy & ProductProxy::operator= ( const ProductProxy pp  ) 

Assignment operator.

The operator checks if the given item differs from this istance and, in this case, it only copies product ID.

References _pid, and _theProduct.

int ProductProxy::uniqueID (  )  const

Return the product unique ID.

Returns:
Product ID

References _pid.

Referenced by Basket::addProduct(), and UserMenu::printCatalog().


Friends And Related Function Documentation

ostream& operator<< ( ostream &  aStream,
ProductProxy pp 
) [friend]

Member Data Documentation

int ProductProxy::_pid [private]

The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2