.
, . , , , , , , .
.
, , , .
, .
, , , .
, On_hand Spare_Part, , , On_hand Spare_Part. , " " , . , optional<On_Hand> Spare_Part.
, , , -
struct On_Hand_Info { int quantity; string location; };
std::map<Spare_Part, On_Hand_Info> on_hand;
, , - :
struct IRetrievalInformation {
virtual int getQuantity() const=0;
};
class SparePart{
string name;
double price;
std::unique_ptr<IRetrievalInformation> retinfo;
public:
Spare_Part();
string const& getName() const { return name; }
double getPrice() const { return price; }
IRetrievalInformation const& getRetrievalInformation() const {
assert(retinfo);
return *retinfo;
}
IRetrievalInformation& getRetrievalInformation() {
return const_cast<IRetrievalInformation&>(
const_cast<SparePart const*>(this)->getRetrievalInformation()
);
}
};
class OnHandRetrieval : public IRetrievalInformation {
int quantity;
string location;
public:
On_hand();
int getQuantity() const final override { return quantity; }
};
PS: , , .