Hi All,
I'm using Swift to develop an app, and am currently building the framework it'll use. I'm currently looking at the display functionality and am building a class of OutputObjects with multiple subclasses, each providing specific functionality.
The data the OutputObjects will represent is also multi-classed and subclassed.
I've implemented protocols on the data to allow OutputObjects to use generics, and that works really well.
However, I'm considering taking it a stage further, and implementing a) enums with multiple outputs (associated values), and b) generic enums.
I'm considering enums with associated as a replacement for static properties. So, for example, within my enum I might have values called image, colour, etc. These will be specific to each sub-class, that is, every time an OutputObject is created for a Bird, it will have (image: "GenericBird", colour: "Green"), for a Seagull it will have (image: "Seagull", colour: "Purple"), and so on. This would replicate static properties but would allow me to manage all such properties in a single place, without needing to recreate each time in each subclass. Is that a worthwhile approach or just wasted effort, or even too great an unnecessary burden at runtime?
I'm also toying with the idea of generic enums, that is, each enum conforming to a protocol. This would make it possible to use switch statements, for example, referencing items from disparate enums, or otherwise handling specific cases. So while it is possible, would it be worthwhile or otherwise, or indeed good or bad practice? I'm aware there could be pitfalls, eg, duplicated enum items in different lists, etc (I'm confident in my naming conventions that there wouldn't be) and the dreaded forgotten "if admin..." case, as well as further potential tight-coupling issues, but would be interested in hearing others.
Do these suggestions make for bad smells? Does the former negate the benefits of the latter, and would static properties on already protocol-conforming objects make both redundant?
I'd be interested to hear what people's opinions are.