What's wrong with many arguments

Whether the code that passes around a lot of arguments was written this way from the start or has grown organically, it is fragile and vulnerable to programmer mistakes. The main problem is that there are, usually, many arguments of the same type, and they can be miscounted. Consider designing a civilization-building game—when a player creates a new city, a corresponding object is constructed. The player gets to choose what facilities to build in the city, and the game sets the options for available resources:

class City {    public:    enum center_t { KEEP, PALACE, CITADEL };    City(size_t number_of_buildings,         size_t number_of_towers,         size_t guard_strength,         center_t center,         bool with_forge,         bool with_granary, bool ...

Get Hands-On Design Patterns with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.