The class ProductProxy is a virtual proxy of class Product. More...
#include <Product.h>
Public Member Functions | |
ProductProxy (const ProductProxy &pp) | |
ProductProxy (int aPid) | |
Constructor with given ID. | |
~ProductProxy () | |
Default destructor. | |
auto_ptr< Category > | getCategory () |
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. | |
ProductProxy & | operator= (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 | |
Product * | getProduct () throw (InvalidArgument) |
Obtain a real instance of the Product. | |
Private Attributes | |
Product * | _theProduct |
int | _pid |
Friends | |
ostream & | operator<< (ostream &, ProductProxy &) |
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.
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.
[in] | aPid | Product unique ID |
References _pid, and _theProduct.
ProductProxy::~ProductProxy | ( | ) |
vector< ProductProxy * > & ProductProxy::catalog | ( | int | aCid = 0 |
) | [static] |
Return the list of products of a given category.
[in] | aCid | The category ID |
References Database::getConnection(), Singleton< Database >::instance(), ProductProxy(), and SQL_CATALOG_PROXY.
Referenced by UserMenu::printCatalog().
int ProductProxy::getAvailability | ( | ) |
Return the product availability.
References getProduct(), ManagedObject::intForKey(), and KEY_PRD_AVAILABILITY.
Referenced by Basket::addProduct().
auto_ptr< Category > ProductProxy::getCategory | ( | ) |
Returns product category.
References Product::getCategory(), and getProduct().
Referenced by UserMenu::printCatalog().
string ProductProxy::getDescr | ( | ) |
Returns product description.
References getProduct(), KEY_PRD_DESCR, and ManagedObject::valueForKey().
string ProductProxy::getName | ( | ) |
Returns product name.
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.
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.
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.
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.
References _pid.
Referenced by Basket::addProduct(), and UserMenu::printCatalog().
ostream& operator<< | ( | ostream & | aStream, | |
ProductProxy & | pp | |||
) | [friend] |
int ProductProxy::_pid [private] |
Referenced by getProduct(), operator=(), ProductProxy(), and uniqueID().
Product* ProductProxy::_theProduct [private] |
Referenced by getProduct(), operator=(), ProductProxy(), and ~ProductProxy().