I am building an app in Angular2 and have a question about how to structure my main class.
I need to create 78 instances of a class. The catch is that not all 78 share the same properties. They share everything but one property. Let's pretend this property is colour. Half of them have a value for colour, half of them don't.
Would you:
A) Divide them into two classes? This seems clunky to me
B) Use a colour decorator and pass those with a colour through the decorator? I think this is the right solution, but I need clarification
C) Something I haven't thought of?
Can you declare colour as optional? Declare it as something like colour?: string.
See https://www.typescriptlang.org/docs/handbook/interfaces.html for some more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With