// Example of a self-documenting interface in C++
class IShape {
public:
virtual ~IShape() = default;
virtual double getArea() const = 0; // Clearly indicates the method's purpose
virtual std::string getName() const = 0; // Discloses the name of the shape
};
class Circle : public IShape {
public:
Circle(double radius) : radius(radius) {}
double getArea() const override {
return 3.14159 * radius * radius; // Implementation of area calculation
}
std::string getName() const override {
return "Circle"; // Provides a clear name descriptor
}
private:
double radius;
};
class Square : public IShape {
public:
Square(double sideLength) : sideLength(sideLength) {}
double getArea() const override {
return sideLength * sideLength; // Implementation of area calculation
}
std::string getName() const override {
return "Square"; // Provides a clear name descriptor
}
private:
double sideLength;
};
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?