sindresorhus / LaunchAtLogin-Legacy

Add “Launch at Login” functionality to your macOS app in seconds
MIT License
1.55k stars 122 forks source link

Why is LaunchAtLogin.swift implemented as enum (and not as class or struct)? #75

Closed mixtly87 closed 2 years ago

mixtly87 commented 2 years ago

Hi @sindresorhus . First of all I think your design of LaunchAtLogin is great!

But I'm just curious why is it implemented as enum?

My impression was that enums should be used to define a common type for a group of related values (case items). I occasionally keep seeing enum being used as much more, like in your example.

I was just wondering what is the benefit? Were there any limitations to implementing logic via class or struct approach?

I have a feel that using enums in the way you did is kind of abusing enums. But it may be well since I come from the Java world originally. Or if you can point to some article were it is justified or encouraged to use enums the way you did.

Note: I'm aware this question is not an Issue in classical sence, I was just curious in the discussion.

Thank you.

sindresorhus commented 2 years ago

enum with static properties is the common convention for imitating namespaces (which Swift lacks).

https://www.swiftbysundell.com/articles/powerful-ways-to-use-swift-enums/