# C++ API design - Should I pass enums as method parameters [closed]

I have two methods which are GetMinimumSize() and GetMaximumSize(). They return the maximum size of the window, and they take one parameter, which is an enum either WindowSizeLimitParam::Width, or WindowSizeLimitParam::Height, because of course, we want to specify which maximum or minimum we want to get.

Here is the enum

enum class WindowSizeLimitParam
{
Width = 0,
Height = 1
};


Some time ago, I didn't have this enum, and I just had 4 methods which were just for min size width, min size height, max size width, and max size height, but for the sake of shortness, I decided to do it with an enum. So my question is, is this a good design choice? Using an enum to specify the size type which we want to get? Keep in mind I have other methods like setting size or getting size, but they don't use enums, they are GetWidth(), GetHeight(), SetWidth(), SetHeight(). If I'm using an enum for the size limit, should i use an enum here and just have SetSize() and GetSize() in which i pass an enum?

Is it generally a good idea to use enums if you are developing an API, which is kind of what I am doing here.

• This question is lacking context, so it won't be possible to produce a sensible review. It sounds like you are asking about this more generally, as opposed to having a particular piece of code about which you are worried. If there is a particular instance you want reviewing, then we need to see how it is used (e.g. which method takes it as a parameter and how is it called). A more general query may be on-topic on the Software Engineering StackExchange. – VisualMelon Aug 21 '19 at 12:24

It's important to be consistent - if you already have GetWidth, GetHeight, SetWidth and SetHeight then it makes sense to have GetMinimumWidth, GetMinimumHeight, GetMaximumWidth, and GetMaximumHeight.

An alternative approach is to retrieve every value in a struct, which further simplifies your API surface and may improve performance if you expect a consumer to call most other getters:

struct WindowSizeInfo
{
const int width, minWidth, maxWidth;
const int height, minHeight, maxHeight;
}

WindowSizeInfo Window::GetSize()
{
return WindowSizeInfo( ... );
}

• Thank you very much. It really is a better way of doing it when I give it a second thought – Christian Panov Feb 18 '19 at 10:56