Class design
- C++ course
- Intermediate
- Lesson 19/116
- 6 min
Design the skeleton of the helper library class.
Project: Helper library
In this 5-lesson project you will build a reusable helper library. Each lesson adds one piece, and by the final lesson you will have a working module. All helpers live inside one class Helpers.
You will use what you learned in previous groups: classes, constructors and inheritance. By making helper methods static you can call them without an instance: Helpers::capitalize("hello"). That is why helper libraries are designed as classes with static methods.
Helpers class skeleton
First we define an empty Helpers class. In the following lessons we will add static methods to it. For now we prepare the skeleton and verify it works with std::cout.
Example: class Helpers { }; defines the empty class. In main, std::cout << "Ready"; shows the program runs. This confirms the skeleton is ready. In the next lessons we will add methods on top of this skeleton, and each lesson's starting code will contain the previous lesson's solution.
Practice Define the Helpers class skeleton
Define a Helpers class with an empty body. In main print "Ready" with std::cout.
Starter code
#include <iostream>
#include <string>
// Define the Helpers class here
int main() {
// Print the Ready message
return 0;
}Sample solution
#include <iostream>
#include <string>
class Helpers {
};
int main() {
std::cout << "Ready";
return 0;
}Expected output
Ready
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does making a helper method static enable?
static std::string capitalize(std::string text);- Lets you call it without an instance Correct answer
- Makes the method faster
- Hides the method
- Makes the method private
Explanation: static methods are called with the class name, no instance needed.
2 Complete the class name
class ____ { };
class Helpers { };
Explanation: Class names use PascalCase: Helpers.
3 Match each piece to its role
| Term | Meaning |
|---|---|
class Helpers { }; |
Class skeleton |
static |
Call without instance |
Helpers::capitalize() |
Static method call |
std::cout |
Writing output |