-1
\$\begingroup\$

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.

\$\endgroup\$

closed as off-topic by Toby Speight, Peter Taylor, dfhwze, Graipher, VisualMelon Aug 21 at 12:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Toby Speight, Peter Taylor, dfhwze, Graipher, VisualMelon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ 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. \$\endgroup\$ – VisualMelon Aug 21 at 12:24
3
\$\begingroup\$

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( ... );
}
\$\endgroup\$
  • \$\begingroup\$ Thank you very much. It really is a better way of doing it when I give it a second thought \$\endgroup\$ – Christian Panov Feb 18 at 10:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.