Concrete Class - RJAE5/2143-OOP GitHub Wiki

Concrete Class

A type of class within OOP that has all methods defined, and subsequently can be instantiated to create an object. That is, no use of any pure virtual functions which are used to make abstract classes and interfaces.

Example

In this example, a concrete class named Concrete is established and instantiated in main, which is the primary use of concrete classes.

class Concrete
{
    float cost;
    std::string brand;
    int cureHours;

public:
    // By defining all methods, this is a "Concrete class"
    Concrete()
    {
        cost = 9.99;
        brand = "CS-Crete";
        cureHours = 24;
    }

    void setCost(float c)
    {cost = c;}

    int getCureHours()
    {return cureHours;}
};

int main()
{
    // Instantiating the class to create an object
    Concrete myCrete;

    // Utilizing the defined methods
    myCrete.setCost(0.99);
    myCrete.getCureHours();
}

Important Notes

  • A concrete class is the most utilized type of class.
  • An inheritance chain typically ends with a concrete class, but they can be used at any or all levels.
  • A concrete class can make use of the virtual keyword and remain a concrete class, it just cannot have a method with a null function body such as: virtual int myFunc() = 0;.
    • Using the example above, virtual void setCost(float c) {cost = c;} would still be a defined function, therefore the class remains concrete.

Sources:

  1. https://softwareengineering.stackexchange.com/questions/221437/concrete-types-as-described-by-stroustrup-c-programming-language-4th-ed